Skip to main content
Version: 0.2.0

is_in_main_process

FunctionPrivateSource

flag: bool = is_in_main_process()

A function used for checking whether the current process is the main process or not.

The checking is implemented by

https://docs.python.org/3/library/multiprocessing.html#multiprocessing.parent_process

Arguments​

Returns​

ArgumentType
Description
flagboolIf True, the current process is the main process. Note that this method is not capable of detecting the process created by the subprocess module.

Examples​

Test the performance of multiprocessing​

import multiprocessing as mproc
import subprocess
from dash_file_cache.utilities import is_in_main_process


def test_proc():
print("multiprocessing:", is_in_main_process())


print("main:", is_in_main_process())
proc = mproc.Process(target=test_proc)
proc.start()
proc.join()
proc.kill()
print(
"subprocess:",
subprocess.check_output(
[
"python",
"-c",
(
"from dash_file_cache.utilities import is_in_main_process;"
"print(is_in_main_process())"
),
],
text=True,
),
)