File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -56,21 +56,22 @@ def __init__(self, thread_cache):
56
56
thread .name = f"Trio worker thread { next (name_counter )} "
57
57
thread .start ()
58
58
59
+ def _handle_job (self ):
60
+ fn , deliver = self ._job
61
+ self ._job = None
62
+ result = outcome .capture (fn )
63
+ # Tell the cache that we're available to be assigned a new
64
+ # job. We do this *before* calling 'deliver', so that if
65
+ # 'deliver' triggers a new job, it can be assigned to us
66
+ # instead of spawning a new thread.
67
+ self ._thread_cache ._idle_workers [self ] = None
68
+ deliver (result )
69
+
59
70
def _work (self ):
60
71
while True :
61
72
if self ._worker_lock .acquire (timeout = IDLE_TIMEOUT ):
62
73
# We got a job
63
- fn , deliver = self ._job
64
- self ._job = None
65
- result = outcome .capture (fn )
66
- # Tell the cache that we're available to be assigned a new
67
- # job. We do this *before* calling 'deliver', so that if
68
- # 'deliver' triggers a new job, it can be assigned to us
69
- # instead of spawning a new thread.
70
- self ._thread_cache ._idle_workers [self ] = None
71
- deliver (result )
72
- del fn
73
- del deliver
74
+ self ._handle_job ()
74
75
else :
75
76
# Timeout acquiring lock, so we can probably exit. But,
76
77
# there's a race condition: we might be assigned a job *just*
You can’t perform that action at this time.
0 commit comments