Skip to content

Commit

Permalink
Fixed #54 -- Do not leak on_done handlers. (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 authored and prologic committed Jan 16, 2017
1 parent 711973e commit 930ca39
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
3 changes: 1 addition & 2 deletions circuits/core/manager.py
Expand Up @@ -544,8 +544,7 @@ def _on_tick(self):

yield state

if not state.timeout:
self.removeHandler(_on_done_handler, "%s_done" % event_name)
self.removeHandler(_on_done_handler, "%s_done" % event_name)

if state.event is not None:
yield CallValue(state.event.value)
Expand Down
46 changes: 46 additions & 0 deletions tests/core/test_memory_leaks.py
@@ -0,0 +1,46 @@
#!/usr/bin/env python
import pytest

from circuits import handler, Component, Event


class call(Event):

"""call Event"""
success = True


class hello(Event):

"""hello Event"""
success = True


class App(Component):
@handler("call")
def _on_call(self):
x = yield self.call(hello())
yield x.value

def hello(self):
return "Hello World!"


@pytest.fixture
def app(request, manager, watcher):
app = App().register(manager)
assert watcher.wait("registered")

def finalizer():
app.unregister()

request.addfinalizer(finalizer)

return app


def test_done_handlers_dont_leak(manager, watcher, app):
manager.fire(call())
manager.fire(call())
assert watcher.wait("call_success")
assert "hello_done" not in app._handlers

0 comments on commit 930ca39

Please sign in to comment.