ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
794 stars 46 forks source link

Can not invoke hunter-trace multiple times #109

Closed vitrun closed 1 year ago

vitrun commented 1 year ago

What I did

  1. Start a long running script by python demo.py
    
    import os
    import time

from hunter import remote remote.install(verbose=False)

while True: print(os.path.join('a', 'b')) time.sleep(1)

2. Invoke `hunter-trace -p THE-PID-OF-ABOVE-SCRIPT` 
It worked as expected:
```text
[...]nvs/py38/lib/python3.8/posixpath.py:83    line         if b.startswith(sep):
[...]nvs/py38/lib/python3.8/posixpath.py:85    line         elif not path or path.endswith(sep):
[...]nvs/py38/lib/python3.8/posixpath.py:88    line         path += sep + b
[...]nvs/py38/lib/python3.8/posixpath.py:82    line         for bin map(os.fspath, p):
[...]nvs/py38/lib/python3.8/posixpath.py:92    line         return path
[...]nvs/py38/lib/python3.8/posixpath.py:92    return    <= join: 'a/b'
  1. Stop the trace client by CTRL-C
  2. Re do step-2 Oops. It complains:
    Failed to activate: AttributeError("'_io.TextIOWrapper' object has no attribute 'get'"). No tracer options.

What I expect

It should be able to re-enter the tracer via client

vitrun commented 1 year ago

It seems that deactivate in remote.py is to blame:

def deactivate():
    hunter._default_config = sys.stderr
    hunter.stop()

It should be hunter._default_config = {}?

ionelmc commented 1 year ago

Gonna release 3.5.1 today if possible.

ionelmc commented 1 year ago

Released now on pypy.