Skip to content

Commit

Permalink
Fixed all bugs related to cancelling, pausing or unpausing a (stopped…
Browse files Browse the repository at this point in the history
…) Coroutine that never yielded any Deferreds
  • Loading branch information
Erik Allik committed Aug 27, 2012
1 parent f64c37f commit 2bca21c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 11 additions & 0 deletions tests.py
Expand Up @@ -203,6 +203,17 @@ def fn2():
assert retval == 'someretval'


def test_pause_unpause_cancel_on_coroutine_with_no_depends_on():
@coroutine
def fn():
yield

c = fn()
c.pause()
c.unpause()
c.cancel()


@contextmanager
def recursion_limit(n):
old = sys.getrecursionlimit()
Expand Down
11 changes: 7 additions & 4 deletions txcoroutine/__init__.py
Expand Up @@ -154,11 +154,13 @@ class Coroutine(Deferred):
depends_on = None

def pause(self):
self.depends_on.pause()
if self.depends_on:
self.depends_on.pause()
return Deferred.pause(self)

def unpause(self):
self.depends_on.unpause()
if self.depends_on:
self.depends_on.unpause()
return Deferred.unpause(self)

def cancel(self):
Expand All @@ -172,8 +174,9 @@ def cancel(self):
# will still get it.
swallow_cancelled_error = lambda f: f.trap(CancelledError)

self.depends_on.addErrback(swallow_cancelled_error)
self.depends_on.cancel()
if self.depends_on:
self.depends_on.addErrback(swallow_cancelled_error)
self.depends_on.cancel()

self.addErrback(swallow_cancelled_error)
Deferred.cancel(self)
Expand Down

0 comments on commit 2bca21c

Please sign in to comment.