Skip to content

Commit

Permalink
Fix unexpected behavior from modified events dict
Browse files Browse the repository at this point in the history
The events dict is now copied to another temporary variable before the
handler functions are called. This way, if the events dict is changed,
the copy stays in tact, and we don't get unexpected behavior.
  • Loading branch information
Ryan Matthews committed Feb 13, 2016
1 parent 8f219af commit 41a3edd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ def emit(self, event, *args, **kwargs):
"""
handled = False

# Copy the events dict first. Avoids a bug if the events dict gets
# changed in the middle of the following for loop.
events_copy = list(self._events[event])

# Pass the args to each function in the events dict
for f in self._events[event]:
for f in events_copy:
f(*args, **kwargs)
handled = True

Expand Down

0 comments on commit 41a3edd

Please sign in to comment.