What class is destroyed? I though you said the module?
Your module works until the interpreter stops. you can add something to run at this time using the "atexit" module:
import atexit
atexit.register(myfunction)
EDIT: based on your comments.
, , . ( , ) atexit:
def close_database():
proceed_to_close()
import atexit
atexit.register(close_database)
.
, . ? ? , ...
, database.py:
class DataBase(object):
@staticmethod
def execute_some_query(query):
code_here()
some_code()
@staticmethod
def close_database():
proceed_to_close()
import atexit ; atexit.register(DataBase.close_database)
:
from database import DataBase
DataBase.execute_some_query(query)
database.py:
def execute_some_query(query):
code_here()
some_code()
def close_database():
proceed_to_close()
import atexit ; atexit.register(close_database)
:
import database
database.execute_some_query(query)
: sqlalchemy .