classification
Title: wsgiref.simple_server.SimpleServer claims to be multithreaded
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, djc, pje, sgala
Priority: normal Keywords: patch

Created on 2010-03-14 18:08 by sgala, last changed 2019-05-24 17:25 by berker.peksag. This issue is now closed.

Files
File name Uploaded Description Edit
multithread.patch sgala, 2014-10-02 21:36 Patch so that simple_server.py doesn't claim falsely it is multithreaded
Pull Requests
URL Status Linked Edit
PR 12977 merged berker.peksag, 2019-04-27 00:00
Messages (6)
msg101058 - (view) Author: Santiago Gala (sgala) Date: 2010-03-14 18:08
In python 2.6, a server created with wsgiref.simple_server.make_server will
claim to be multithreaded and multiprocess through it wsgi environ. See  wsgi.multithread in the browser page after launching

  $ python /usr/lib/python2.6/wsgiref/simple_server.py

The bug is due to the default value in the constructor wsgiref.handlers.SimpleHandler, and it is misleading, as the servier is singlethreaded. It gives problems for any app that wants to change behavior or error on singlethreaded.

The problem can be fixed very simply by patching a "multithreaded=False" argument into the ServerHandler constructor in simple_server.
msg228121 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-10-01 21:05
@Santiago can you provide a patch for this issue?
msg228262 - (view) Author: Santiago Gala (sgala) Date: 2014-10-02 21:36
Something like this should do it:

$ diff -u /usr/lib/python2.7/wsgiref/simple_server.py{~,}
--- /usr/lib/python2.7/wsgiref/simple_server.py~	2014-10-02 23:32:47.718382895 +0200
+++ /usr/lib/python2.7/wsgiref/simple_server.py	2014-10-02 14:36:10.662220865 +0200
@@ -118,7 +118,8 @@
             return
 
         handler = ServerHandler(
-            self.rfile, self.wfile, self.get_stderr(), self.get_environ()
+            self.rfile, self.wfile, self.get_stderr(), self.get_environ(),
+            multithread = False
         )
         handler.request_handler = self      # backpointer for logging
         handler.run(self.server.get_app())
msg228539 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-10-05 04:45
Looks like Werkzeug had a workaround for this bug:

    https://github.com/mitsuhiko/werkzeug/commit/f9e2fad30d34a6b0737539434c03c07c2bc658d4
msg340952 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2019-04-27 00:01
It's not easy to write a test for this, so I might merge PR 12977 without a test.
msg343413 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2019-05-24 17:24
New changeset 14738ff83d852c95a0cf33e5c90a85860a9c5620 by Berker Peksag in branch 'master':
bpo-8138: Initialize wsgiref's SimpleServer as single-threaded (GH-12977)
https://github.com/python/cpython/commit/14738ff83d852c95a0cf33e5c90a85860a9c5620
History
Date User Action Args
2019-05-24 17:25:12berker.peksagsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: - Python 3.7
2019-05-24 17:24:46berker.peksagsetmessages: + msg343413
2019-04-27 00:01:28berker.peksagsetmessages: + msg340952
versions: + Python 3.7, Python 3.8, - Python 2.7, Python 3.4, Python 3.5
2019-04-27 00:00:19berker.peksagsetpull_requests: + pull_request12903
2019-04-26 17:52:10BreamoreBoysetnosy: - BreamoreBoy
2014-10-05 04:45:59berker.peksagsetmessages: + msg228539
2014-10-05 03:44:56berker.peksagsetnosy: + berker.peksag

stage: patch review
2014-10-02 21:36:10sgalasetfiles: + multithread.patch
keywords: + patch
messages: + msg228262
2014-10-01 21:05:50BreamoreBoysetnosy: + BreamoreBoy

messages: + msg228121
versions: + Python 2.7, Python 3.4, Python 3.5, - Python 2.6
2010-08-03 14:24:19djcsetnosy: + djc
2010-07-12 14:19:06BreamoreBoysetnosy: + pje
2010-03-14 18:11:33sgalasettype: behavior
components: + Library (Lib)
2010-03-14 18:08:54sgalacreate