-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-32608: Adding a server into socketserver that handles client connection in new "multiprocessing.Process" processes. #5258
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
base: main
Are you sure you want to change the base?
Conversation
…e passed into sub-processes created by the multiprocessing package.
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
I signed the CLA yesterday, does it take a few days for that to be seen? |
Doc/library/socketserver.rst
Outdated
The :class:`ForkingMixIn` class is used in the same way, except that the server | ||
will spawn a new process for each request. | ||
The :class:`ForkingMixIn` and :class:`ProcessingMixIn` classes can be used in | ||
the same way, except that the server will spawn a new process for each request. | ||
Available only on POSIX platforms that support :func:`~os.fork`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably ProcessingMixIn
can be used on Windows, since multiprocessing.Process
can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, that was my intent.
Since the multiprocessing.Process object is more portable, it makes sense to potentially use that if a developer wanted to. I didn't think removing the existing ForkingMixIn class would be productive since that would break anything that uses it, and there is probably still good use cases to use a lighter weight "os.fork()" implementation on POSIX systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I had meant to say there was that the documentation was incorrect by implying that ProcessingMixIn was posix-only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand now, it wasn't necessarily documentation that I changed but more documentation that I didn't change. I'm updating the rst file now.
If interested, the specific comment for this comment is:
15ec16b
…ggesting ProcessingMixIn (and associated server classes) can still be used on non-POSIX systems.
…after each test, which caused the tests to fail.
For my own sanity, I'm dropping some useful commands I used when building/testing these changes. Linux builds:
Windows builds:
|
Can someone with more Python on Windows experience be able to explain to me why the AppVeyor build is failing? To me, it looks like the AppVeyor is failing on the I would like this pull-request to get merged as soon as we can, but I doubt it will make it much farther with one of the build checks failing. -- Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for posting this PR. I posted some comments below.
Also, it seems the tests fail on Windows (see the AppVeyor CI failure).
@@ -99,11 +99,12 @@ server classes. | |||
|
|||
|
|||
.. class:: ForkingMixIn | |||
ProcessingMixIn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add a versionadded
marker for the new class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
:class:`ForkingMixIn` and the Forking classes mentioned below are | ||
only available on POSIX platforms that support :func:`~os.fork`. | ||
|
||
.. class:: ForkingTCPServer | ||
ForkingUDPServer | ||
ProcessingTCPServer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here (need a versionadded
marker).
Doc/whatsnew/3.7.rst
Outdated
@@ -969,6 +969,13 @@ Changes in the Python API | |||
work as expected on all platforms. | |||
(Contributed by Yury Selivanov in :issue:`32331`.) | |||
|
|||
* New :mod:`socketserver` classes were added called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet will have to go into 3.8.rst
instead. (also, make sure to add a "Contributed by..." note in parentheses as in the other entries).
Lib/socketserver.py
Outdated
# above max_children. | ||
while len(self.active_children) >= self.max_children: | ||
try: | ||
pid, _ = os.waitpid(-1, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think using waitpid
is ok with the multiprocessing version. Instead, use either one of the Process
methods (perhaps join()
) or the multiprocessing.connection.wait
function if you need to wait on multiple objects (see https://docs.python.org/3/library/multiprocessing.html#multiprocessing.connection.wait ).
Lib/test/test_socketserver.py
Outdated
# The ProcessingTCPServer and ProcessingUDPServer both modify the | ||
# environment, specifically the "multiprocessing.process._dangling" | ||
# WeakSet() of created processes. | ||
self._multiproc_dangling = multiprocessing.process._dangling.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a bug. Perhaps you need to call Process.join
at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this some more, I think you're right. I've refactored the logic a little bit so that the tests do not need to clean up dangling processes.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
…multiprocessing # Conflicts: # Doc/whatsnew/3.7.rst
…ess.join() is called, rather than os.waitpid()
…ngling" references; and fixed some test_socketserver tests.
Hi Antoine (pitrou). I've made the changes you suggested. However the CI builds fail on Windows because of dangling threads that I cannot seem to track down why. Do you have a few minutes have a second set of eyes looking at the errors? Locally, I print a traceback in I added this into
This bug is close to being complete, I cannot figure out why the Process objects are creating these extra threads that are not being cleaned up. -- Thanks! |
…server_and_multiprocessing # Conflicts: # Doc/whatsnew/3.8.rst # Lib/socketserver.py
I have looked at the code over and over again. I keep coming to the conclusion that the reason the AppVeyor tests are failing only on Windows is because there is a problem with the way Windows handles multiple processes. For some reason, on Windows there is a dangling thread laying around after the unit tests run. I just cannot find exactly where and why a thread gets created but never cleaned up in the This scenario does not happen on Linux systems, which leads me to believe this problem is a bit out of scope of this ticket. Can someone look and confirm? I'd really like to close this ticket so it can be merged into the main baseline, however the failing tests on Windows seems to be preventing this ticket from advancing. |
AppVeyor spotted a dangling thread:
|
@vstinner, Yup I see that there is a dangling thread. I cannot see what is different when running on Windows that produces the dangling thread that does not happen on Linux. |
Updating fork with that of the upstream.
Updating socketserver_and_multiprocessing with that of master.
This PR is stale because it has been open for 30 days with no activity. |
FWIW, this could still be merged in, I just never had the time or experience to figure out why the Windows CI tests failed. I've tested the branch on Windows directly and it passed. I do not understand why the CI was failing, but directly on a Windows host passed. |
This PR is stale because it has been open for 30 days with no activity. |
https://bugs.python.org/issue32608