itamarst / eliot

Eliot: the logging system that tells you *why* it happened
https://eliot.readthedocs.io
Apache License 2.0
1.11k stars 66 forks source link

Switch to using contextvars, in order to support Trio #397

Closed itamarst closed 5 years ago

itamarst commented 5 years ago

Fixes #290 Fixes #396

itamarst commented 5 years ago

This is broken. I need to switch to using just ContextVar.set/get, without managing our own stack; the latter is no longer necessary. And tests to demonstrate the problems I saw with Trio example.

itamarst commented 5 years ago

Should in theory work now, modulo minor fixes.

itamarst commented 5 years ago

@jtrakk would appreciate some testing, if you have the time.

jtrakk commented 5 years ago

I'm not sure what's supposed to happen if I continue an action in a subprocess (trio.Process) and an exception is raised inside that subprocess.

[...]
  File "/usr/lib/python3.7/contextlib.py", line 511, in __exit__
    raise exc_details[1]
  File "/usr/lib/python3.7/contextlib.py", line 496, in __exit__
    if cb(*exc_details):
  File "/usr/lib/python3.7/contextlib.py", line 377, in _exit_wrapper
    return cm_exit(cm, exc_type, exc, tb)
  File "/home/user/Documents/project/venv/lib/python3.7/site-packages/eliot/_action.py", line 414, in __exit__
    _ACTION_CONTEXT.reset(self._parent_token)
ValueError: <Token var=<ContextVar name='eliot.action' at 0x7f51b550c048> at 0x7f51b3f631f8> was created in a different Context
itamarst commented 5 years ago

Could you share a minimal reproducer? Thanks!

jtrakk commented 5 years ago

The issue was due to my broken dual-purpose logging decorator implementation. I'll keep poking around and will update if I experience problems.