File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -802,8 +802,9 @@ def run_in_background(
802
802
deferred returned by the function completes.
803
803
804
804
To explain how the log contexts work here:
805
- - When this function is called, the current context is stored ("original"), we kick
806
- off the background task, and we restore that original context before returning
805
+ - When `run_in_background` is called, the current context is stored ("original"),
806
+ we kick off the background task in the current context, and we restore that
807
+ original context before returning
807
808
- When the background task finishes, we don't want to leak our context into the
808
809
reactor which would erroneously get attached to the next operation picked up by
809
810
the event loop. We add a callback to the deferred which will clear the logging
@@ -828,6 +829,7 @@ def run_in_background(
828
829
"""
829
830
calling_context = current_context ()
830
831
try :
832
+ # (kick off the task in the current context)
831
833
res = f (* args , ** kwargs )
832
834
except Exception :
833
835
# the assumption here is that the caller doesn't want to be disturbed
Original file line number Diff line number Diff line change @@ -286,9 +286,11 @@ async def run() -> Optional[R]:
286
286
).dec ()
287
287
288
288
# To explain how the log contexts work here:
289
- # - When this function is called, the current context is stored (using
290
- # `PreserveLoggingContext`), we kick off the background task, and we restore the
291
- # original context before returning (also part of `PreserveLoggingContext`).
289
+ # - When `run_as_background_process` is called, the current context is stored
290
+ # (using `PreserveLoggingContext`), we kick off the background task, and we
291
+ # restore the original context before returning (also part of
292
+ # `PreserveLoggingContext`).
293
+ # - The background task runs in its own new logcontext named after `desc`
292
294
# - When the background task finishes, we don't want to leak our background context
293
295
# into the reactor which would erroneously get attached to the next operation
294
296
# picked up by the event loop. We use `PreserveLoggingContext` to set the
You can’t perform that action at this time.
0 commit comments