Skip to content
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

wsgiref.simple_server.SimpleServer claims to be multithreaded #52385

Closed
sgala mannequin opened this issue Mar 14, 2010 · 6 comments
Closed

wsgiref.simple_server.SimpleServer claims to be multithreaded #52385

sgala mannequin opened this issue Mar 14, 2010 · 6 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sgala
Copy link
Mannequin

sgala mannequin commented Mar 14, 2010

BPO 8138
Nosy @pjeby, @djc, @berkerpeksag
PRs
  • bpo-8138: Initialize wsgiref's SimpleServer as single-threaded #12977
  • Files
  • multithread.patch: Patch so that simple_server.py doesn't claim falsely it is multithreaded
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-24.17:25:12.677>
    created_at = <Date 2010-03-14.18:08:54.920>
    labels = ['3.8', 'type-bug', 'library']
    title = 'wsgiref.simple_server.SimpleServer claims to be multithreaded'
    updated_at = <Date 2019-05-24.17:25:12.676>
    user = 'https://bugs.python.org/sgala'

    bugs.python.org fields:

    activity = <Date 2019-05-24.17:25:12.676>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-24.17:25:12.677>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2010-03-14.18:08:54.920>
    creator = 'sgala'
    dependencies = []
    files = ['36787']
    hgrepos = []
    issue_num = 8138
    keywords = ['patch']
    message_count = 6.0
    messages = ['101058', '228121', '228262', '228539', '340952', '343413']
    nosy_count = 4.0
    nosy_names = ['pje', 'sgala', 'djc', 'berker.peksag']
    pr_nums = ['12977']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8138'
    versions = ['Python 3.8']

    @sgala
    Copy link
    Mannequin Author

    sgala mannequin commented Mar 14, 2010

    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.

    @sgala sgala mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 14, 2010
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Oct 1, 2014

    @santiago can you provide a patch for this issue?

    @sgala
    Copy link
    Mannequin Author

    sgala mannequin commented Oct 2, 2014

    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())

    @berkerpeksag
    Copy link
    Member

    Looks like Werkzeug had a workaround for this bug:

    https://github.com/mitsuhiko/werkzeug/commit/f9e2fad30d34a6b0737539434c03c07c2bc658d4
    

    @berkerpeksag
    Copy link
    Member

    It's not easy to write a test for this, so I might merge PR 12977 without a test.

    @berkerpeksag berkerpeksag added 3.7 (EOL) end of life 3.8 only security fixes labels Apr 27, 2019
    @berkerpeksag
    Copy link
    Member

    New changeset 14738ff by Berker Peksag in branch 'master':
    bpo-8138: Initialize wsgiref's SimpleServer as single-threaded (GH-12977)
    14738ff

    @berkerpeksag berkerpeksag removed the 3.7 (EOL) end of life label May 24, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant