-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Spawning multiprocessing workers on Windows changes mouse cursor #118293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 25, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 26, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 26, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 26, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 26, 2024
tunedal
pushed a commit
to tunedal/cpython
that referenced
this issue
Apr 26, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 26, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 26, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 27, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 27, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 27, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 27, 2024
tunedal
added a commit
to tunedal/cpython
that referenced
this issue
Apr 27, 2024
zooba
pushed a commit
that referenced
this issue
Apr 28, 2024
…esses with multiprocessing (GH-118315)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Bug report
Bug description:
The multiprocessing module uses the CreateProcess function on Windows to spawn processes, which has a flag for controlling whether Windows should display feedback to the user in the form of the "Working in Background cursor" (i.e. pointer and hourglass/circle) while the process is launching (see
STARTF_FORCEONFEEDBACK
in the docs for STARTUPINFO). Since multiprocessing doesn't specify any flags, it gets the default behavior, resulting in this launch feedback mouse cursor being displayed whenever a worker process is spawned.Since processes in multiprocessing are used as an alternative to threads, not for launching applications but for running background tasks in an existing application, I believe it would make sense to disable the launch feedback. The application is already running and can provide its own UI for displaying the state of background tasks, just as it would when using threads, so the extra feedback is not needed. The launch feedback is more confusing than helpful when launching a background task, because it's not tied to the lifetime of the task – it's just displayed for some arbitrary period of time until it times out waiting for the worker process to display its UI, which it never will.
It's particularly confusing in the case of process pools: The user will see some feedback the first time a task is submitted to the pool (when it starts a worker process) but nothing when subsequent tasks are submitted. And, as mentioned above, it doesn't actually tell the user anything about whether the task is finished, so it's not a useful feature to rely on for this. (Tkinter applications that need a reliable busy cursor can presumably use the new functions added in #72684.)
To fix this, pass the
STARTF_FORCEOFFFEEDBACK
flag in the STARTUPINFO structure when calling CreateProcess. The relevant Python code is in the multiprocessing.popen_spawn_win32 module, which currently passesNone
for this parameter.Screenshot of running a background task with

threading.Thread
– no mouse cursor change:Screenshot of running the same task with

multiprocessing.Process
– mouse cursor changes when launching the task:Steps to reproduce the issue:
.pyw
files) usingpythonw.exe
– the issue is not reproducible from a console application.Expected behavior:
The two buttons should exhibit identical behavior. The mouse cursor should not change in either case.
Actual behavior:
Unlike the "Run Thread task" button, the "Run Process task" button will result in a "Working in Background cursor" being displayed for a few seconds. The cursor will then change back before the task is actually completed (which happens after 10 seconds, as indicated by the app's UI).
The attached demo script lets you monkeypatch the multiprocessing module at runtime by checking the "Enable patch" checkbox. The steps above will then produce the expected behavior.
CPython versions tested on:
3.10, 3.11
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: