Fix #131947: Error closing prefs while installing extensions on WIN32
Using `signal.SIGINT` to send a signal to a sub-process isn't supported on WIN32, replace with `signal.CTRL_BREAK_EVENT`.
This commit is contained in:
committed by
Philipp Oeser
parent
6e0232fc71
commit
51b3864ae0
@@ -232,7 +232,13 @@ def command_output_from_json_0(
|
||||
# Note that the context-manager isn't used to wait until the process is finished as
|
||||
# the function only finishes when `poll()` is not none, it's just use to ensure file-handles
|
||||
# are closed before this function exits, this only seems to be a problem on WIN32.
|
||||
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as ps:
|
||||
|
||||
# WIN32 needs to use a separate process-group else Blender will recieve the "break", see #131947.
|
||||
creationflags = 0
|
||||
if sys.platform == "win32":
|
||||
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
|
||||
|
||||
with subprocess.Popen(cmd, stdout=subprocess.PIPE, creationflags=creationflags) as ps:
|
||||
stdout = ps.stdout
|
||||
assert stdout is not None
|
||||
|
||||
@@ -291,7 +297,11 @@ def command_output_from_json_0(
|
||||
# It also means a request to exit might not be responded to soon enough.
|
||||
request_exit = yield json_messages
|
||||
if request_exit and not request_exit_signal_sent:
|
||||
ps.send_signal(signal.SIGINT)
|
||||
if sys.platform == "win32":
|
||||
# Caught by the `signal.SIGBREAK` signal handler.
|
||||
ps.send_signal(signal.CTRL_BREAK_EVENT)
|
||||
else:
|
||||
ps.send_signal(signal.SIGINT)
|
||||
request_exit_signal_sent = True
|
||||
|
||||
|
||||
|
||||
@@ -5579,6 +5579,9 @@ def main(
|
||||
|
||||
# Run early to prevent a `KeyboardInterrupt` exception.
|
||||
signal.signal(signal.SIGINT, signal_handler_sigint)
|
||||
if sys.platform == "win32":
|
||||
# WIN32 needs to check for break as sending SIGINT isn't supported from the caller, see #131947.
|
||||
signal.signal(signal.SIGBREAK, signal_handler_sigint)
|
||||
|
||||
# Needed on WIN32 which doesn't default to `utf-8`.
|
||||
for fh in (sys.stdout, sys.stderr):
|
||||
|
||||
Reference in New Issue
Block a user