#20238: StoppableWSGIServer is not multithread support
-----------------------------------+--------------------------------------
Reporter: jwxiao@… | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Comment (by Aymeric Augustin):
The following monkey-patch does the job for me.
{{{
import socketserver
from django.test import testcases
class ThreadedWSGIServer(socketserver.ThreadingMixIn,
testcases.WSGIServer):
"""
Make Django's live server test case multi-threaded.
See https://code.djangoproject.com/ticket/20238#comment:6
"""
testcases.WSGIServer = ThreadedWSGIServer
}}}
I'm using the PostgreSQL database backend.
I don't think this proposal is sufficient for in-memory SQLite. A
WSGIHandler subclass that replaces the database connection for each new
thread by the database connection from the main thread is likely needed.
----
By the way, this piece of code in `django.core.servers.basehttp`:
{{{
if threading:
httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn,
WSGIServer), {})
else:
httpd_cls = WSGIServer
}}}
could be replaced with:
{{{
httpd_cls = ThreadedWSGIServer if threading else WSGIServer
}}}
assuming the definition of `ThreadedWSGIServer` above.
There's no reason (that I can think of) to define a class dynamically
like that here. Saving a couple lines isn't worth the obfuscation.
--
Ticket URL: <https://code.djangoproject.com/ticket/20238#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/074.14590e929a9920e828623136cffd43bf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.