Eryk Sun <[email protected]> added the comment:
spawn_main() could handle a PermissionError by checking the exit code. If the
parent has terminated already, then simply exit quietly.
_winapi.PROCESS_QUERY_LIMITED_INFORMATION would need to be defined. For example:
def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None):
"""Run code specified by data received over a pipe."""
assert is_forking(sys.argv), "Not forking"
if sys.platform == 'win32':
import msvcrt
import _winapi
if parent_pid is not None:
source_process = _winapi.OpenProcess(
_winapi.SYNCHRONIZE |
_winapi.PROCESS_DUP_HANDLE |
_winapi.PROCESS_QUERY_LIMITED_INFORMATION,
False, parent_pid)
else:
source_process = None
try:
new_handle = reduction.duplicate(
pipe_handle, source_process=source_process)
fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY)
exitcode = _main(fd, source_process)
except PermissionError:
if (source_process is None or
_winapi.GetExitCodeProcess(source_process) ==
_winapi.STILL_ACTIVE):
raise
exitcode = 1
else:
from . import resource_tracker
resource_tracker._resource_tracker._fd = tracker_fd
exitcode = _main(pipe_handle, os.dup(pipe_handle))
sys.exit(exitcode)
----------
stage: -> needs patch
type: -> behavior
versions: +Python 3.10 -Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38263>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com