mirror of
https://github.com/jazzband/django-ddp.git
synced 2026-03-16 22:40:24 +00:00
Move dddp.main.greenify() to dddp.greenify() to avoid import of threading module before green thread init.
This commit is contained in:
parent
b9a17b8f37
commit
86c8a68f88
3 changed files with 19 additions and 14 deletions
|
|
@ -5,6 +5,7 @@ from pkg_resources import get_distribution, DistributionNotFound
|
|||
from gevent.local import local
|
||||
from dddp import alea
|
||||
|
||||
|
||||
try:
|
||||
_dist = get_distribution('django-ddp')
|
||||
if not __file__.startswith(os.path.join(_dist.location, 'django-ddp', '')):
|
||||
|
|
@ -18,6 +19,18 @@ else:
|
|||
default_app_config = 'dddp.apps.DjangoDDPConfig'
|
||||
|
||||
|
||||
def greenify():
|
||||
"""Patch threading and psycopg2 modules for green threads."""
|
||||
if 'threading' in sys.modules:
|
||||
raise Exception('threading module loaded before patching!')
|
||||
|
||||
from gevent.monkey import patch_all
|
||||
patch_all()
|
||||
|
||||
from psycogreen.gevent import patch_psycopg
|
||||
patch_psycopg()
|
||||
|
||||
|
||||
class AlreadyRegistered(Exception):
|
||||
|
||||
"""Raised when registering over the top of an existing registration."""
|
||||
|
|
|
|||
16
dddp/main.py
16
dddp/main.py
|
|
@ -9,18 +9,6 @@ import sys
|
|||
Addr = collections.namedtuple('Addr', ['host', 'port'])
|
||||
|
||||
|
||||
def greenify():
|
||||
"""Patch threading and psycopg2 modules for green threads."""
|
||||
if 'threading' in sys.modules:
|
||||
raise Exception('threading module loaded before patching!')
|
||||
|
||||
from gevent.monkey import patch_all
|
||||
patch_all()
|
||||
|
||||
from psycogreen.gevent import patch_psycopg
|
||||
patch_psycopg()
|
||||
|
||||
|
||||
def ddpp_sockjs_xhr(environ, start_response):
|
||||
"""Dummy method that doesn't handle XHR requests."""
|
||||
start_response(
|
||||
|
|
@ -200,10 +188,10 @@ def main():
|
|||
'listen', metavar='address[:port]', nargs='*', type=addr,
|
||||
)
|
||||
namespace = parser.parse_args()
|
||||
# monkey patch stdlib for gevent.
|
||||
greenify()
|
||||
serve(namespace.listen or [Addr('localhost', 8000)])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from dddp import greenify
|
||||
greenify()
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
|
||||
|
||||
from dddp import greenify
|
||||
greenify()
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
|
|
|
|||
Loading…
Reference in a new issue