File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 77
88import atexit
99import contextvars
10+ import functools
1011import io
1112import os
1213import sys
@@ -620,10 +621,19 @@ def flush(self):
620621 else :
621622 self ._flush ()
622623
624+ @property
623625 def _flush (self ):
626+ """Prepare _flush_impl partial to be scheduled on the IO thread.
627+
628+ This indirection is necessary to ensure _flush_impl calls hooks
629+ registered from the current thread (as they are thread-local).
630+ """
631+ return functools .partial (self ._flush_impl , self ._hooks )
632+
633+ def _flush_impl (self , hooks = ()):
624634 """This is where the actual send happens.
625635
626- _flush should generally be called in the IO thread,
636+ _flush_impl should generally be called in the IO thread,
627637 unless the thread has been destroyed (e.g. forked subprocess).
628638 """
629639 self ._flush_pending = False
@@ -648,7 +658,7 @@ def _flush(self):
648658 # Each transform either returns a new
649659 # message or None. If None is returned,
650660 # the message has been 'used' and we return.
651- for hook in self . _hooks :
661+ for hook in hooks :
652662 msg = hook (msg )
653663 if msg is None :
654664 return
You can’t perform that action at this time.
0 commit comments