From 16e48e50bef20578d433ad1ae6d81141e1fb14a9 Mon Sep 17 00:00:00 2001 From: Tyson Clugg Date: Sun, 14 Jun 2015 00:02:29 +1000 Subject: [PATCH] Don't barf on multiple invocations of greenify(). --- dddp/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dddp/__init__.py b/dddp/__init__.py index a2d4dcd..7c3c404 100644 --- a/dddp/__init__.py +++ b/dddp/__init__.py @@ -26,10 +26,9 @@ REMOVED = 'removed' def greenify(): """Patch threading and psycopg2 modules for green threads.""" - if 'threading' in sys.modules: + from gevent.monkey import patch_all, saved + if ('threading' in sys.modules) and ('threading' not in saved): raise Exception('threading module loaded before patching!') - - from gevent.monkey import patch_all patch_all() from psycogreen.gevent import patch_psycopg