Skip to content

Fix iteration in Bus.stop_all_periodic_tasks #637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions can/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,21 @@ def _send_periodic_internal(self, msgs, period, duration=None):
return task

def stop_all_periodic_tasks(self, remove_tasks=True):
"""Stop sending any messages that were started using bus.send_periodic
"""Stop sending any messages that were started using **bus.send_periodic**.

.. note::
The result is undefined if a single task throws an exception while being stopped.

:param bool remove_tasks:
Stop tracking the stopped tasks.
"""
for task in self._periodic_tasks:
task.stop(remove_task=remove_tasks)
# we cannot let `task.stop()` modify `self._periodic_tasks` while we are
# iterating over it (#634)
task.stop(remove_task=False)

if remove_tasks:
self._periodic_tasks = []

def __iter__(self):
"""Allow iteration on messages as they are received.
Expand Down