mysqlkivykivy-languagekivymdpyjnius

Close the database connection when kivy app gets killed


I have created a small kivy app. Here, I have made use of mysql database. When the kivy app gets killed or destroyed ,I want to close the database connection. How will I know if my kivy app is running in background or destroyed.


Solution

  • to close database connection, you can set wait timeout parameter with minimum value which have 8 hours by default. So if database will have any idle connection, same will be killed by MySQL server itself.

    Let's say, if we set wait_timeout 60 seconds. then idle connection will be active for 60 seconds only. after 60 seconds, connection will be released. To change required variable, Please use below steps:

    mysql -uUSER -pPASSWORD

    then

    set global variables wait_timeout=60;

    or you can also set this variable for your kivy app only with session variables