diff options
| author | albanD <desmaison.alban@gmail.com> | 2023-08-23 20:27:35 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-23 20:27:35 (GMT) |
| commit | 1700d34d314f5304a7a75363bda295a8c15c371f (patch) | |
| tree | 75b99c018ab6a09c3eec9c510d8dee128644831d /Lib/multiprocessing/synchronize.py | |
| parent | 5d1871576500adc4ebaa7f59b8559605a57ad36b (diff) | |
| download | cpython-1700d34d314f5304a7a75363bda295a8c15c371f.zip cpython-1700d34d314f5304a7a75363bda295a8c15c371f.tar.gz cpython-1700d34d314f5304a7a75363bda295a8c15c371f.tar.bz2 | |
gh-77377: Ensure multiprocessing SemLock is valid for spawn-based Process before serializing it (#107275)
Ensure multiprocessing SemLock is valid for spawn Process before serializing it.
Creating a multiprocessing SemLock with a fork context, and then trying to pass it to a spawn-created Process, would segfault if not detected early.
---------
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Diffstat (limited to 'Lib/multiprocessing/synchronize.py')
| -rw-r--r-- | Lib/multiprocessing/synchronize.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py index 42624b5..2328d33 100644 --- a/Lib/multiprocessing/synchronize.py +++ b/Lib/multiprocessing/synchronize.py @@ -50,8 +50,8 @@ class SemLock(object): def __init__(self, kind, value, maxvalue, *, ctx): if ctx is None: ctx = context._default_context.get_context() - name = ctx.get_start_method() - unlink_now = sys.platform == 'win32' or name == 'fork' + self.is_fork_ctx = ctx.get_start_method() == 'fork' + unlink_now = sys.platform == 'win32' or self.is_fork_ctx for i in range(100): try: sl = self._semlock = _multiprocessing.SemLock( @@ -103,6 +103,11 @@ class SemLock(object): if sys.platform == 'win32': h = context.get_spawning_popen().duplicate_for_child(sl.handle) else: + if self.is_fork_ctx: + raise RuntimeError('A SemLock created in a fork context is being ' + 'shared with a process in a spawn context. This is ' + 'not supported. Please use the same context to create ' + 'multiprocessing objects and Process.') h = sl.handle return (h, sl.kind, sl.maxvalue, sl.name) |
