Skip to content

Commit

Permalink
Merge #103
Browse files Browse the repository at this point in the history
103: Fix (another) thread leak in ThrottleExecutor r=rohanpm a=rohanpm

The thread's main loop did "del executor" before waiting on the event,
but it could still hold a reference to the executor from 'to_submit'
or 'job'.

Fixes #93

Co-authored-by: Rohan McGovern <rohan@mcgovern.id.au>
  • Loading branch information
bors[bot] and rohanpm committed Jan 6, 2019
2 parents a8c792e + 5d20a53 commit b61f87b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/api-reference.rst
Expand Up @@ -133,6 +133,13 @@ The poll function has the following semantics:
- If the poll function returns an int or float, it is used as the delay
in seconds until the next poll.

.. warning::

The poll function should avoid holding a reference to the corresponding
:class:`~more_executors.poll.PollExecutor`. If it holds a reference to the
executor, invoking :meth:`~concurrent.futures.Executor.shutdown` becomes
mandatory in order to stop the polling thread.

.. _cancel function:


Expand Down
13 changes: 11 additions & 2 deletions docs/user-guide.rst
Expand Up @@ -184,5 +184,14 @@ For example, this code is broken:
with executor:
do_something(executor)
Shutting down executors is optional and is not necessary to (eventually)
reclaim resources.
Generally, shutting down executors is optional and is not necessary to
(eventually) reclaim resources.

However, where executors accept caller-provided code (such as the polling
function to :class:`~more_executors.poll.PollExecutor` or the retry
policy to :class:`~more_executors.retry.RetryExecutor`), it is easy to
accidentally create a circular reference between the provided code and the
executor. When this happens, it will no longer be possible for the garbage
collector to clean up the executor's resources automatically and a thread
leak may occur. If in doubt, call
:meth:`~concurrent.futures.Executor.shutdown`.

0 comments on commit b61f87b

Please sign in to comment.