Repository navigation
support Request termination for gevent - #9440
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9440 +/- ##
==========================================
- Coverage 78.16% 78.15% -0.01%
==========================================
Files 153 153
Lines 19025 19029 +4
Branches 2518 2518
==========================================
+ Hits 14870 14873 +3
- Misses 3866 3867 +1
Partials 289 289
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
To make it more likely for def _make_killable_target(target):
def killable_target(*args, **kwargs):
from greenlet import GreenletExit
try:
return target(*args, **kwargs)
except GreenletExit:
import time
time.sleep(1) # <<<<<
return (False, None, None)This does show that the greenlet may get killed twice and therefore capturing GreenletExit for cleanup will not always work. Alternatively we can not return the greenlet from class TaskPool(base.BasePool):
"""GEvent Pool."""
def on_apply(self, target, args=None, kwargs=None, callback=None,
accept_callback=None, timeout=None,
timeout_callback=None, apply_target=apply_target, **_):
timeout = self.timeout if timeout is None else timeout
target = self._make_killable_target(target)
greenlet = self._quick_put(apply_timeout if timeout else apply_target,
target, args, kwargs, callback, accept_callback,
self.getpid, timeout=timeout, timeout_callback=timeout_callback)
self._add_to_pool_map(id(greenlet), greenlet)I'm not sure what the side-effects are of this. @Nusnus What do you think is the best? |
|
A third option would be to bind an dummy function class TaskPool(base.BasePool):
"""GEvent Pool."""
def on_apply(...):
...
greenlet.terminate = types.MethodType(_terminate, greenlet)
return greenlet
def _terminate(self, signal):
# Done in `TaskPool.terminate_job`
passThis way the greenlet gets killed only once and we return a result handler from |
|
I went for the third option in the end: |
522fafe to
b0c49a3
Compare
Nusnus
left a comment
There was a problem hiding this comment.
@Nusnus What do you think is the best?
TBH I am not completely sure, but the 3rd (and current) option appears to be a simple fix, which is favorable.
I’ve postponed the final release in favor of another RC which I’ll release tomorrow.
I’ll include this patch, and let’s see if the issue gets resolved.
|
PR #9083 adds support for terminating gevent jobs.
I can confirm @dwick observation #9083 (comment)_
The reason is this
In this MR was bind
terminateto the greenlet instance when returned fromon_apply.