Commit 1d294b22 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

BF: Sigh. Needed a more robust method of detecting the main process.

parent 019f1246
......@@ -75,6 +75,12 @@ def main(argv=None):
# that have been specified.
# Flag ourselves as the main
# process, so child processes
# can tell that they are not
# the main process. = mp.current_process().pid
if args.plugin_file is not None:
for p in args.plugin_file:
......@@ -220,13 +220,18 @@ def inMainProcess():
"""Returns ``True`` if the running process is the main (parent) process.
Returns ``False`` if the running process is a child process (e.g. a
``multiprocessingg`` worker process).
.. note:: This function depends on the main process settings its pid as
an attribute on this function called ``pid``.
# see docs for -
# child processes will have a
# name matching this pattern
p = mp.current_process()
return not re.fullmatch(r'Proceess-\d+',
mainpid = getattr(inMainProcess, 'pid', None)
if mainpid is None:
raise RuntimeError('inMainProcess needs to be initialised '
'by the main process!')
return mp.current_process().pid == mainpid
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment