From 4f361be7e722f87d0edc469f21d97cc666560342 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 18 Mar 2018 19:02:11 +0545 Subject: [PATCH] issue #144: teach Select() to close its latch Causes all threads sleeping on the select to wake. --- docs/api.rst | 16 +++++++++++++--- mitogen/master.py | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 0b420749..56850232 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -159,6 +159,11 @@ contexts. :return: :py:class:`mitogen.core.Message` + :raises mitogen.core.TimeoutError: + Timeout was reached. + :raises mitogen.core.LatchError: + :py:meth:`close` has been called, and the underlying latch is no + longer valid. .. py:method:: __bool__ () @@ -166,9 +171,14 @@ contexts. .. py:method:: close () - Remove the select's notifier function from each registered receiver. - Necessary to prevent memory leaks in long-running receivers. This is - called automatically when the Python :keyword:`with` statement is used. + Remove the select's notifier function from each registered receiver, + mark the associated latch as closed, and cause any thread currently + sleeping in :py:meth:`get` to be woken with + :py:class:`mitogen.core.LatchError`. + + This is necessary to prevent memory leaks in long-running receivers. It + is called automatically when the Python :keyword:`with` statement is + used. .. py:method:: empty () diff --git a/mitogen/master.py b/mitogen/master.py index ea7fd4ff..2fc55c5d 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -236,6 +236,7 @@ class Select(object): def close(self): for recv in self._receivers[:]: self.remove(recv) + self._latch.close() def empty(self): return self._latch.empty()