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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
get_or_raise_if_dead
get_or_raise_if_dead(result_q, process, poll_interval=1.0)
Wait for one item from result_q, raising if process exits without sending it.
result_q.get() alone blocks forever if the helper process dies first, for example from
an uncaught exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_q
|
Queue
|
Queue the helper process puts its result on. |
required |
process
|
BaseProcess
|
The helper process. |
required |
poll_interval
|
float
|
Seconds between checks that the helper process is still alive. |
1.0
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Source code in zeus/utils/multiprocessing.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |