Commit bfe5bb68 authored by Denis Bilenko's avatar Denis Bilenko

Greenlet: set _start_event if greenlet was killed or switched to

parent 72e94e75
...@@ -216,7 +216,9 @@ class Greenlet(greenlet): ...@@ -216,7 +216,9 @@ class Greenlet(greenlet):
a) cancel the event that will start it a) cancel the event that will start it
b) fire the notifications as if an exception was raised in a greenlet b) fire the notifications as if an exception was raised in a greenlet
""" """
if self._start_event is not None: if self._start_event is None:
self._start_event = _dummy_event
else:
self._start_event.stop() self._start_event.stop()
try: try:
greenlet.throw(self, *args) greenlet.throw(self, *args)
...@@ -297,7 +299,9 @@ class Greenlet(greenlet): ...@@ -297,7 +299,9 @@ class Greenlet(greenlet):
`Changed in version 0.13.0:` *block* is now ``True`` by default. `Changed in version 0.13.0:` *block* is now ``True`` by default.
""" """
if self._start_event is not None: if self._start_event is None:
self._start_event = _dummy_event
else:
self._start_event.stop() self._start_event.stop()
if not self.dead: if not self.dead:
waiter = Waiter() waiter = Waiter()
...@@ -390,7 +394,10 @@ class Greenlet(greenlet): ...@@ -390,7 +394,10 @@ class Greenlet(greenlet):
def run(self): def run(self):
try: try:
self._start_event.stop() if self._start_event is None:
self._start_event = _dummy_event
else:
self._start_event.stop()
try: try:
result = self._run(*self.args, **self.kwargs) result = self._run(*self.args, **self.kwargs)
except: except:
...@@ -473,6 +480,15 @@ class Greenlet(greenlet): ...@@ -473,6 +480,15 @@ class Greenlet(greenlet):
self.parent.handle_error((link, self), *sys.exc_info()) self.parent.handle_error((link, self), *sys.exc_info())
class _dummy_event(object):
def stop(self):
pass
_dummy_event = _dummy_event()
def _kill(greenlet, exception, waiter): def _kill(greenlet, exception, waiter):
try: try:
greenlet.throw(exception) greenlet.throw(exception)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment