multiprocessing
zeus.utils.multiprocessing
Multiprocessing-related utilities.
_is_global_in_spawned_child
_is_global_in_spawned_child()
Return True if called from module-level code in a spawned child's main script.
In a spawned child process (using the "spawn" start method), the main script
is re-imported with __name__ = "__mp_main__" instead of "__main__". This
function detects if we're currently executing module-level code (like global
variable initialization) in such a script.
This walks the call stack looking for any __name__ is "__mp_main__".
Source code in zeus/utils/multiprocessing.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
warn_if_global_in_subprocess
warn_if_global_in_subprocess(self)
Warn when a monitor is created at import time in a spawned subprocess.
This detects a common pitfall where ZeusMonitor (or related classes) is instantiated as a global variable or called from module-level code. When the script spawns subprocesses using the "spawn" method, the subprocess re-imports the main module, causing global initialization code to run again (e.g., loading DNN models), leading to OOM errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
self |
Any
|
The instance being constructed (used to derive class name). |
required |
Source code in zeus/utils/multiprocessing.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |