Skip to content

Commit

Permalink
Fix issue with the thread_local_stream leaking context
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed May 6, 2024
1 parent 5df4b51 commit 84969ba
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rerun_py/rerun_sdk/rerun/recording_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class RecordingStream:
with rec:
rr.log(...)
```
WARNING: if using a RecordingStream as a context manager, you cannot yield from a generator function
while holding the context. This will leak the context and likely cause your program to send data
to the wrong stream. See: https://github.com/rerun-io/rerun/issues/6238
See also: [`rerun.get_data_recording`][], [`rerun.get_global_data_recording`][],
[`rerun.get_thread_local_data_recording`][].
Expand Down Expand Up @@ -442,11 +445,14 @@ def decorator(func: _TFunc) -> _TFunc:
@functools.wraps(func)
def generator_wrapper(*args: Any, **kwargs: Any) -> Any:
gen = func(*args, **kwargs)
stream = new_recording(application_id, recording_id=uuid.uuid4())
try:
with new_recording(application_id, recording_id=uuid.uuid4()):
with stream:
value = next(gen) # Start the generator inside the context
while True:
value = gen.send((yield value)) # Continue the generator
while True:
cont = yield value # Continue the generator
with stream:
value = gen.send(cont)
except StopIteration:
pass
finally:
Expand Down

0 comments on commit 84969ba

Please sign in to comment.