ProcessDb
Use this class to create a background process that can use the db.
Class that extends multiprocessing.Process to allow to use the db in the subprocess. It clears the db connection before starting the process.
This is useful when you want to run a task in the background without waiting for it to finish, but the task needs a clean database connection.
Example: def my_task(arg1, arg2): # This function will run in a separate process with clean db connection results = MyModel.select() # ... do work ...
# Start the process
process = ProcessDb(target=my_task, args=(value1, value2))
process.start()
# Optionally wait for it to finish
process.join()
:param Process: multiprocessing.Process :type Process: type
Initialize the ProcessDb
AnyCallablestrboolClose the Process object.
This method releases resources held by the Process object. It is an error to call this method if the child process is still running.
Return whether process is alive
Wait until child process terminates
AnyTerminate process; sends SIGKILL signal or uses TerminateProcess()
Override the run method to reset db connections before running the target function
Start child process
Terminate process; sends SIGTERM signal or uses TerminateProcess()