[Pkg-bitcoin-commits] [python-quamash] 260/269: Fix bug when removing after closing

Jonas Smedegaard dr at jones.dk
Fri Nov 24 11:26:42 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 a34ab1e5227d432bea8255ba0fae57ddc9df1a31
Author: Inso <insomniak.fr at gmail.com>
Date:   Wed Dec 23 11:23:28 2015 +0100

    Fix bug when removing after closing
---
 quamash/__init__.py      | 13 +++++++++++++
 tests/test_qeventloop.py | 18 ++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/quamash/__init__.py b/quamash/__init__.py
index 927fccd..13b2e43 100644
--- a/quamash/__init__.py
+++ b/quamash/__init__.py
@@ -310,6 +310,11 @@ class QEventLoop(_baseclass):
 
 		The loop cannot be restarted after it has been closed.
 		"""
+		if self.is_running():
+			raise RuntimeError("Cannot close a running event loop")
+		if self.is_closed():
+			return
+
 		self._logger.debug('Closing event loop...')
 		if self.__default_executor is not None:
 			self.__default_executor.shutdown()
@@ -397,6 +402,10 @@ class QEventLoop(_baseclass):
 
 	def remove_reader(self, fd):
 		"""Remove reader callback."""
+
+		if self.is_closed():
+			return
+
 		self._logger.debug('Removing reader callback for file descriptor {}'.format(fd))
 		try:
 			notifier = self._read_notifiers.pop(fd)
@@ -429,6 +438,10 @@ class QEventLoop(_baseclass):
 
 	def remove_writer(self, fd):
 		"""Remove writer callback."""
+
+		if self.is_closed():
+			return
+
 		self._logger.debug('Removing writer callback for file descriptor {}'.format(fd))
 		try:
 			notifier = self._write_notifiers.pop(fd)
diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index 84a74a3..5e0cbb4 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -399,6 +399,24 @@ def test_can_remove_reader(loop, sock_pair):
 
 	assert got_msg is None, 'Should not have received a read notification'
 
+def test_can_remove_reader_after_closing(loop, sock_pair):
+	"""Verify that we can remove a reader callback from an event loop."""
+	def can_read():
+		data = srv_sock.recv(1)
+		if len(data) != 1:
+			return
+
+		nonlocal got_msg
+		got_msg = data
+
+	client_sock, srv_sock = sock_pair
+
+	got_msg = None
+	loop.add_reader(srv_sock.fileno(), can_read)
+	loop.close()
+	loop.remove_reader(srv_sock.fileno())
+
+	assert got_msg is None, 'Should not have received a read notification'
 
 def test_can_add_writer(loop, sock_pair):
 	"""Verify that we can add a writer callback to an event loop."""

-- 
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