[Python-ideas] Idea: Allow multiple levels of tracers

Ram Rachum ram.rachum at gmail.com
Sun Apr 28 04:12:42 EDT 2019


It's possible, but it would be very cumbersome, for a bunch of reasons. One
of them is that the tracing code inspects the frame, the variables
referenced in it, and it even opens the file of the code object of the
frame. It will be difficult to mock all of that, and even if that's
possible, we won't have high confidence that the mock is reliable.

On Sun, Apr 28, 2019, 11:06 Barry Scott <barry at barrys-emacs.org> wrote:

>
>
> On 25 Apr 2019, at 15:51, Ram Rachum <ram at rachum.com> wrote:
>
> Hi,
>
> Here's something I want in Python: Multiple levels of tracers working on
> top of each other, instead of just one.
>
> I'm talking about the tracer that one can set by calling sys.settrace.
>
> I've recently released PySnooper: https://github.com/cool-RR/PySnooper/
>
> One of the difficulties I have, is that I can't debug or run the
> `coverage` tool on the core of this module. That's because the core is a
> trace function, and debuggers and coverage tools work by setting a trace
> function. When PySnooper sets its trace function using `sys.settrace`, the
> code that runs in that trace function runs without getting traced by the
> coverage tracer.
>
> This means that people who develop debuggers and coverage tools can't use
> a debugger or a coverage tool on the core of their tool. It's quite an
> annoying problem.
>
> My proposed solution: Multiple levels of tracing, instead of just one.
> When you install a tracer, you're not replacing the existing one, you're
> appending a tracer to the existing list of tracers.
>
> If this was implemented, then when PySnooper would install its tracer, the
> coverage tracer would still be active and running, for every line of code
> including the ones in PySnooper's tracer.
>
> Obviously, we'll need to figure out the API and any other kind of problems
> with this proposal.
>
> What do you think?
>
>
> Personally I would look to other means to get the coverage report for a
> tracing tool
> or debugger.
>
> For example why not use unittesting and mocking to allow the trace code to
> be run
> and measured? After all you only have to mock for one functions interface.
>
> As for debugging I would use print() or logging to find what I need.
>
> Barry
>
>
>
> Thanks,
> Ram.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190428/c8094b74/attachment-0001.html>


More information about the Python-ideas mailing list