Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

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

Functions
__init__

Initialize the ProcessDb

group : Any
reserved for future extension
target : Callable
the callable object to be invoked by the run() method
name : str
the process name
daemon : bool
whether the process is a daemon
close

Close 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.

is_alive

Return whether process is alive

join

Wait until child process terminates

timeout : Any
kill

Terminate process; sends SIGKILL signal or uses TerminateProcess()

run

Override the run method to reset db connections before running the target function

start

Start child process

terminate

Terminate process; sends SIGTERM signal or uses TerminateProcess()

Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.