Skip to main content

is_in_main_process

FunctionPrivateSource

flag: bool = is_in_main_process()

A function used for checking whether the str ends with a line break.

The checking is implemented by

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

We use this function to fix the missing final line break problem of str.splitlines.

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,
),
)