[Pkg-bitcoin-commits] [python-quamash] 137/269: Disable QSocketNotifier while calling read/write callbacks
Jonas Smedegaard
dr at jones.dk
Fri Nov 24 11:26:24 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository python-quamash.
commit c41268758b8330be85cf1d0615502a8dca669887
Author: Arve Knudsen <arve.knudsen at gmail.com>
Date: Tue Nov 25 18:09:28 2014 +0100
Disable QSocketNotifier while calling read/write callbacks
---
quamash/__init__.py | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/quamash/__init__.py b/quamash/__init__.py
index 9cfb845..ea748c7 100644
--- a/quamash/__init__.py
+++ b/quamash/__init__.py
@@ -337,7 +337,9 @@ class QEventLoop(_baseclass):
notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Read)
notifier.setEnabled(True)
self._logger.debug('Adding reader callback for file descriptor {}'.format(fd))
- notifier.activated.connect(lambda: callback(*args))
+ notifier.activated.connect(
+ lambda: self.__on_notifier_ready(notifier, callback, args)
+ )
self._read_notifiers[fd] = notifier
def remove_reader(self, fd):
@@ -351,7 +353,9 @@ class QEventLoop(_baseclass):
notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Write)
notifier.setEnabled(True)
self._logger.debug('Adding writer callback for file descriptor {}'.format(fd))
- notifier.activated.connect(lambda: callback(*args))
+ notifier.activated.connect(
+ lambda: self.__on_notifier_ready(notifier, callback, args)
+ )
self._write_notifiers[fd] = notifier
def remove_writer(self, fd):
@@ -360,6 +364,17 @@ class QEventLoop(_baseclass):
notifier = self._write_notifiers.pop(fd)
notifier.setEnabled(False)
+ @staticmethod
+ def __on_notifier_ready(notifier, callback, args):
+ # It can be necessary to disable QSocketNotifier when e.g. checking
+ # ZeroMQ sockets for events
+ enabled = notifier.isEnabled()
+ notifier.setEnabled(False)
+ try:
+ callback(*args)
+ finally:
+ notifier.setEnabled(enabled)
+
# Methods for interacting with threads.
@_easycallback
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/python-quamash.git
More information about the Pkg-bitcoin-commits
mailing list