[pytango] 28/122: Fix #58: server gevent mode internal call hangs (PR #59)
Sandor Bodo-Merle
sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:18:15 UTC 2017
This is an automated email from the git hooks/post-receive script.
sbodomerle-guest pushed a commit to tag v9.2.1
in repository pytango.
commit f3c64d3fb6c31d0495ed615250618d3706cc80a4
Author: Tiago Coutinho <coutinhotiago at gmail.com>
Date: Thu Sep 22 10:18:26 2016 +0200
Fix #58: server gevent mode internal call hangs (PR #59)
- worker checks if it is in gevent thread. If so simply executes tasks
- serialize requests coming from clients to prevent blocking issue
---
tango/server.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tango/server.py b/tango/server.py
index 69181f3..36af53f 100644
--- a/tango/server.py
+++ b/tango/server.py
@@ -1599,6 +1599,7 @@ def _create_gevent_worker():
from queue import Queue
except:
from Queue import Queue
+ from threading import current_thread
import gevent
import gevent.event
@@ -1633,11 +1634,16 @@ def _create_gevent_worker():
self.__stop_event = gevent.event.Event()
self.__watcher = gevent.get_hub().loop.async()
self.__watcher.start(self.__step)
+ self.__lock = gevent._threading.Lock()
+ self.__id = id(current_thread())
def __step(self):
task = self.__tasks.get()
return task.run()
+ def is_gevent_thread(self):
+ return self.__id == id(current_thread())
+
def run_in_thread(self, func, *args, **kwargs):
thread_id = gevent._threading.start_new_thread(func, args, kwargs)
return thread_id
@@ -1647,11 +1653,14 @@ def _create_gevent_worker():
timeout=timeout)
def execute(self, func, *args, **kwargs):
+ if self.is_gevent_thread():
+ return func(*args, **kwargs)
event = gevent._threading.Event()
task = self.Task(event, func, *args, **kwargs)
- self.__tasks.put(task)
- self.__watcher.send()
- event.wait()
+ with self.__lock:
+ self.__tasks.put(task)
+ self.__watcher.send()
+ event.wait()
if task.exception:
if issubclass(task.exception[0], DevFailed):
raise task.exception[1]
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git
More information about the debian-science-commits
mailing list