This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SIGSEGV when access a fork Event in a spawn Process
Type: crash Stage:
Components: Documentation Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, iritkatriel, kemingy
Priority: normal Keywords:

Created on 2021-09-27 01:33 by kemingy, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg402687 - (view) Author: Keming (kemingy) Date: 2021-09-27 01:33
Code to trigger this problem:

```python
import multiprocessing as mp
from time import sleep


def wait_for_event(event):
    while not event.is_set():
        sleep(0.1)


def trigger_segment_fault():
    event = mp.get_context("fork").Event()
    p = mp.get_context("spawn").Process(target=wait_for_event, args=(event,))
    p.start()  # this will show the exitcode=-SIGSEGV
    sleep(1)
    print(p)
    event.set()
    p.terminate()


if __name__ == "__main__":
    trigger_segment_fault()
```

Accessing this forked event in a spawned process will result in a segment fault.

I have found a related report: https://bugs.python.org/issue43832. But I think it's not well documented in the Python 3 multiprocessing doc.

Will it be better to explicit indicate that the event is related to the start method context in the documentation?
msg411412 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-23 19:45
Which python version and system are you seeing this on?

On 3.11 on a Mac I don't get a segfault but rather 

Process SpawnProcess-1:
Traceback (most recent call last):
  File "/Users/iritkatriel/src/cpython/Lib/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
    ^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython/Lib/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython/tt.py", line 6, in wait_for_event
    while not event.is_set():
              ^^^^^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython/Lib/multiprocessing/synchronize.py", line 328, in is_set
    with self._cond:
    ^^^^^^^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython/Lib/multiprocessing/synchronize.py", line 230, in __enter__
    return self._lock.__enter__()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython/Lib/multiprocessing/synchronize.py", line 95, in __enter__
    return self._semlock.__enter__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 9] Bad file descriptor
<SpawnProcess name='SpawnProcess-1' pid=29612 parent=29610 stopped exitcode=1>
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89461
2022-01-23 19:45:31iritkatrielsetnosy: + iritkatriel
messages: + msg411412
2021-09-27 01:33:14kemingycreate