@@ -395,9 +395,7 @@ async def __call__(self, *args, **kwargs):
395
395
if hasattr (AsyncToSync .executors , "current" ):
396
396
# If we have a parent sync thread above somewhere, use that
397
397
executor = AsyncToSync .executors .current
398
- elif self .thread_sensitive_context and self .thread_sensitive_context .get (
399
- None
400
- ):
398
+ elif self .thread_sensitive_context .get (None ):
401
399
# If we have a way of retrieving the current context, attempt
402
400
# to use a per-context thread pool executor
403
401
thread_sensitive_context = self .thread_sensitive_context .get ()
@@ -412,15 +410,14 @@ async def __call__(self, *args, **kwargs):
412
410
elif loop in AsyncToSync .loop_thread_executors :
413
411
# Re-use thread executor for running loop
414
412
executor = AsyncToSync .loop_thread_executors [loop ]
415
- elif self .deadlock_context and self . deadlock_context .get (False ):
413
+ elif self .deadlock_context .get (False ):
416
414
raise RuntimeError (
417
415
"Single thread executor already being used, would deadlock"
418
416
)
419
417
else :
420
418
# Otherwise, we run it in a fixed single thread
421
419
executor = self .single_thread_executor
422
- if self .deadlock_context :
423
- self .deadlock_context .set (True )
420
+ self .deadlock_context .set (True )
424
421
else :
425
422
# Use the passed in executor, or the loop's default if it is None
426
423
executor = self ._executor
@@ -449,8 +446,7 @@ async def __call__(self, *args, **kwargs):
449
446
450
447
finally :
451
448
_restore_context (context )
452
- if self .deadlock_context :
453
- self .deadlock_context .set (False )
449
+ self .deadlock_context .set (False )
454
450
455
451
return ret
456
452
0 commit comments