-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
Open
deliberist
wants to merge
17
commits into
python:main
Choose a base branch
from
deliberist:socketserver_and_multiprocessing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
da98359
Adding a server into socketserver that allows client connections to b…
deliberist 15ec16b
bpo-32608: updated socketserver.rst based on pull-request comments su…
deliberist 5444d6b
bpo-32608: Adding documentation into Doc/whatsnew and Misc/NEWS.d/nex…
deliberist f7de7b9
bpo-32608: Fixed test_socketserver where it modified the environment …
deliberist 535f13d
Merge remote-tracking branch 'upstream/master' into socketserver_and_…
deliberist f84538d
Merge remote-tracking branch 'upstream/master' into socketserver_and_…
deliberist 5eee0ea
Merge remote-tracking branch 'upstream/master' into socketserver_and_…
deliberist cd209db
bpo-32608: Per PR-5258 comments: moved documentation to Python 3.8 fi…
deliberist 28f397d
bpo-32608: Per PR-5258 comments: made the ProcessingMixIn ensure Proc…
deliberist 22bdab7
bpo-32608: Per PR-5258 comments, removed "multiprocessing.process._da…
deliberist 9adc823
bpo-32608: fixing errors with test_socketserver in a Windows environm…
deliberist 1f32fd7
bpo-32608: Fixing broken test_socketserver tests when run in Linux.
deliberist ef2fd3b
bpo-32608: Fixing broken test_socketserver tests when run in Windows.
deliberist 7097ae6
bpo-32608: Merge remote-tracking branch 'upstream/master' into socket…
deliberist 61ef9f8
Merge pull request #1 from python/master
77d2cb2
Merge branch 'socketserver_and_multiprocessing' into master
18d14fd
Merge pull request #2 from rbprogrammer/master
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,8 +44,8 @@ completed before the next request can be started. This isn't suitable if each | |
| request takes a long time to complete, because it requires a lot of computation, | ||
| or because it returns a lot of data which the client is slow to process. The | ||
| solution is to create a separate process or thread to handle each request; the | ||
| :class:`ForkingMixIn` and :class:`ThreadingMixIn` mix-in classes can be used to | ||
| support asynchronous behaviour. | ||
| :class:`ForkingMixIn`, :class:`ProcessingMixIn`, and :class:`ThreadingMixIn` | ||
| mix-in classes can be used to support asynchronous behaviour. | ||
|
|
||
| Creating a server requires several steps. First, you must create a request | ||
| handler class by subclassing the :class:`BaseRequestHandler` class and | ||
|
|
@@ -99,11 +99,14 @@ server classes. | |
|
|
||
|
|
||
| .. class:: ForkingMixIn | ||
| ProcessingMixIn | ||
| ThreadingMixIn | ||
|
|
||
| Forking and threading versions of each type of server can be created | ||
| using these mix-in classes. For instance, :class:`ThreadingUDPServer` | ||
| is created as follows:: | ||
| .. versionadded:: 3.8 | ||
|
|
||
| Forking, multiprocessing, and threading versions of each type of server can | ||
| be created using these mix-in classes. For instance, | ||
| :class:`ThreadingUDPServer` is created as follows:: | ||
|
|
||
| class ThreadingUDPServer(ThreadingMixIn, UDPServer): | ||
| pass | ||
|
|
@@ -112,6 +115,17 @@ server classes. | |
| :class:`UDPServer`. Setting the various attributes also changes the | ||
| behavior of the underlying server mechanism. | ||
|
|
||
| The :class:`ForkingMixIn` and :class:`ProcessingMixIn` classes are very | ||
| similar in terms of diverting the request connection to a child process. | ||
| :class:`ForkingMixIn` does this by spawning a child process via the low-level | ||
| :func:`~os.fork` method, while :class:`ProcessingMixIn` does this via the | ||
| :class:`multiprocessing.Process` object. | ||
|
|
||
| Determining which mix-in class to use depends on the specific scenario for | ||
| the server. The :class:`ForkingMixIn` is best suited for light-weight | ||
| applications, while the :class:`ProcessingMixIn` is best suited for | ||
| applications that make heavy use of the :mod:`multiprocessing` module. | ||
|
|
||
| :class:`ForkingMixIn` and the Forking classes mentioned below are | ||
| only available on POSIX platforms that support :func:`~os.fork`. | ||
|
|
||
|
|
@@ -137,9 +151,13 @@ server classes. | |
|
|
||
| .. class:: ForkingTCPServer | ||
| ForkingUDPServer | ||
| ProcessingTCPServer | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here (need a |
||
| ProcessingUDPServer | ||
| ThreadingTCPServer | ||
| ThreadingUDPServer | ||
|
|
||
| .. versionadded:: 3.8 | ||
|
|
||
| These classes are pre-defined using the mix-in classes. | ||
|
|
||
|
|
||
|
|
@@ -162,7 +180,7 @@ On the other hand, if you are building an HTTP server where all data is stored | |
| externally (for instance, in the file system), a synchronous class will | ||
| essentially render the service "deaf" while one request is being handled -- | ||
| which may be for a very long time if a client is slow to receive all the data it | ||
| has requested. Here a threading or forking server is appropriate. | ||
| has requested. Here a threading, processing, or forking server is appropriate. | ||
|
|
||
| In some cases, it may be appropriate to process part of a request synchronously, | ||
| but to finish processing in a forked child depending on the request data. This | ||
|
|
@@ -595,8 +613,8 @@ The output of the example should look exactly like for the TCP server example. | |
| Asynchronous Mixins | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To build asynchronous handlers, use the :class:`ThreadingMixIn` and | ||
| :class:`ForkingMixIn` classes. | ||
| To build asynchronous handlers, use the :class:`ThreadingMixIn`, | ||
| :class:`ForkingMixIn`, and :class:`ProcessingMixIn` classes. | ||
|
|
||
| An example for the :class:`ThreadingMixIn` class:: | ||
|
|
||
|
|
@@ -656,7 +674,11 @@ The output of the example should look something like this: | |
| Received: Thread-4: Hello World 3 | ||
|
|
||
|
|
||
| The :class:`ForkingMixIn` class is 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`. | ||
| On POSIX platforms that support :func:`~os.fork`, both 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 as opposed to a new thread. | ||
|
|
||
| On systems that do not support :func:`~os.fork`, the :class:`ProcessingMixIn` is | ||
| still available since it relies on :class:`multiprocessing.Process` to spawn new | ||
| processes. The :class:`ForkingMixIn` class is not available on systems that do | ||
| not support :func:`~os.fork`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
versionaddedmarker 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.