diff options
author | Mark Spruiell <mes@zeroc.com> | 2017-03-15 16:20:52 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2017-03-15 16:20:52 -0700 |
commit | 1c73c503727e526888d1f2fb44e9550a60ec140d (patch) | |
tree | b464fab04ed054945cff4a3950615fb0c9dc36fd | |
parent | VS 2017 UWP support (diff) | |
download | ice-1c73c503727e526888d1f2fb44e9550a60ec140d.tar.bz2 ice-1c73c503727e526888d1f2fb44e9550a60ec140d.tar.xz ice-1c73c503727e526888d1f2fb44e9550a60ec140d.zip |
ICE-7669 - Better fix for Python dispatcher
-rw-r--r-- | python/python/Ice.py | 14 | ||||
-rw-r--r-- | python/test/Ice/dispatcher/AllTests.py | 18 | ||||
-rwxr-xr-x | python/test/Ice/dispatcher/Dispatcher.py | 7 |
3 files changed, 27 insertions, 12 deletions
diff --git a/python/python/Ice.py b/python/python/Ice.py index aa33ea3ad1a..f85b654917e 100644 --- a/python/python/Ice.py +++ b/python/python/Ice.py @@ -122,12 +122,15 @@ class Future(FutureBase): with self._condition: return self._state in [Future.StateCancelled, Future.StateDone] - def add_done_callback(self, fn): + def add_done_callback(self, fn, dispatcher=None): with self._condition: if self._state == Future.StateRunning: self._doneCallbacks.append(fn) return - fn(self) + if dispatcher: + dispatcher(lambda: fn(self)) + else: + fn(self) def result(self, timeout=None): with self._condition: @@ -230,13 +233,16 @@ class InvocationFuture(Future): with self._condition: return self._sentSynchronously - def add_sent_callback(self, fn): + def add_sent_callback(self, fn, dispatcher=None): with self._condition: if not self._sent: self._sentCallbacks.append(fn) return if self._sentSynchronously or not self._asyncResult: - fn(self, self._sentSynchronously) + if dispatcher: + dispatcher(lambda: fn(self, self._sentSynchronously)) + else: + fn(self, self._sentSynchronously) else: self._asyncResult.callLater(lambda: fn(self, self._sentSynchronously)) diff --git a/python/test/Ice/dispatcher/AllTests.py b/python/test/Ice/dispatcher/AllTests.py index b6967a9d5f9..6f03fca86b6 100644 --- a/python/test/Ice/dispatcher/AllTests.py +++ b/python/test/Ice/dispatcher/AllTests.py @@ -32,24 +32,24 @@ class Callback: def response(self, f): test(f.exception() is None) - self.checkThread() + test(Dispatcher.Dispatcher.isDispatcherThread()) self.called() def exception(self, f): test(isinstance(f.exception(), Ice.NoEndpointException)) - self.checkThread() + test(Dispatcher.Dispatcher.isDispatcherThread()) self.called() def exceptionEx(self, f): test(isinstance(f.exception(), Ice.InvocationTimeoutException)) - self.checkThread() + test(Dispatcher.Dispatcher.isDispatcherThread()) self.called() def payload(self, f): if f.exception(): test(isinstance(f.exception(), Ice.CommunicatorDestroyedException)) else: - self.checkThread() + test(Dispatcher.Dispatcher.isDispatcherThread()) def checkThread(self): # @@ -70,6 +70,8 @@ def allTests(communicator, collocated): testController = Test.TestIntfControllerPrx.uncheckedCast(obj) + dispatcher = Dispatcher.Dispatcher.instance() + sys.stdout.write("testing dispatcher... ") sys.stdout.flush() @@ -77,21 +79,21 @@ def allTests(communicator, collocated): cb = Callback() - p.opAsync().add_done_callback(cb.response) + p.opAsync().add_done_callback(cb.response, dispatcher.dispatchSync) cb.check() # # Expect NoEndpointException. # i = p.ice_adapterId("dummy") - i.opAsync().add_done_callback(cb.exception) + i.opAsync().add_done_callback(cb.exception, dispatcher.dispatchSync) cb.check() # # Expect InvocationTimeoutException. # to = p.ice_invocationTimeout(250); - to.sleepAsync(500).add_done_callback(cb.exceptionEx) + to.sleepAsync(500).add_done_callback(cb.exceptionEx, dispatcher.dispatchSync) cb.check() testController.holdAdapter() @@ -106,7 +108,7 @@ def allTests(communicator, collocated): f = None while True: f = p.opWithPayloadAsync(seq) - f.add_done_callback(cb.payload) + f.add_done_callback(cb.payload, dispatcher.dispatchSync) if not f.is_sent_synchronously(): break testController.resumeAdapter() diff --git a/python/test/Ice/dispatcher/Dispatcher.py b/python/test/Ice/dispatcher/Dispatcher.py index 809f7500920..1c48b947a84 100755 --- a/python/test/Ice/dispatcher/Dispatcher.py +++ b/python/test/Ice/dispatcher/Dispatcher.py @@ -29,6 +29,9 @@ class Dispatcher: if len(self._calls) == 1: self._cond.notify() + def dispatchSync(self, call): + self.dispatch(call, None) + def run(self): while True: call = None @@ -60,3 +63,7 @@ class Dispatcher: @staticmethod def isDispatcherThread(): return threading.current_thread() == Dispatcher._instance._thread + + @staticmethod + def instance(): + return Dispatcher._instance |