<div dir="auto"><div>To clarify, I meant that each trace function would manually call any trace functions that were registered below it, instead of using the trampoline in cpython. Does that solve the problem you raised?<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 25, 2019, 20:20 Ned Batchelder <<a href="mailto:ned@nedbatchelder.com">ned@nedbatchelder.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <p>Perhaps I misunderstand what's implied by "simple(!) monkeypatch
      of sys.settrace", but the trickiest part of Ram's proposal is that
      the body of one trace function would still trigger the remaining
      trace functions.  That to me sounds like it's going to require
      changes to ceval.c</p>
    <p>--Ned.<br>
    </p>
    <div class="m_-5459406463158614336moz-cite-prefix">On 4/25/19 12:26 PM, Ram Rachum wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Hmm, looks like, for this to work, you'll need the
        existing tracer to be cooperative. Right now there are existing
        tracers, for example coverage's tracer and Wing IDE's tracer,
        and I would need to modify them for your idea to work, right?
        <div><br>
        </div>
        <div>If I understand your idea correctly, the first tracer would
          monkeypatch `sys.settrace` so whenever someone else adds a
          tracer, it doesn't really do `sys.settrace` but just add a
          function that the real tracer would be calling after it's done
          tracing. But this can't really be done without the original
          tracer implementing it, right?</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Thu, Apr 25, 2019 at 6:16
          PM Ram Rachum <<a href="mailto:ram@rachum.com" target="_blank" rel="noreferrer">ram@rachum.com</a>> wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div dir="ltr">Oh wow, I didn't even consider that. I think
            you're right, I'll do more thinking about this. Thanks
            Anders!</div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Thu, Apr 25, 2019 at
              6:10 PM Anders Hovmöller <<a href="mailto:boxed@killingar.net" target="_blank" rel="noreferrer">boxed@killingar.net</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
              <div dir="auto">
                <div dir="ltr">Can't this be implemented today by a
                  simple monkey patch of sys.settrace?</div>
                <div dir="ltr"><br>
                  On 25 Apr 2019, at 16:51, Ram Rachum <<a href="mailto:ram@rachum.com" target="_blank" rel="noreferrer">ram@rachum.com</a>> wrote:<br>
                  <br>
                </div>
                <blockquote type="cite">
                  <div dir="ltr">
                    <div dir="ltr">Hi,
                      <div><br>
                      </div>
                      <div>Here's something I want in Python: Multiple
                        levels of tracers working on top of each other,
                        instead of just one. </div>
                      <div><br>
                      </div>
                      <div>I'm talking about the tracer that one can set
                        by calling sys.settrace.</div>
                      <div><br>
                      </div>
                      <div>I've recently released PySnooper: <a href="https://github.com/cool-RR/PySnooper/" target="_blank" rel="noreferrer">https://github.com/cool-RR/PySnooper/</a></div>
                      <div><br>
                      </div>
                      <div>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.</div>
                      <div><br>
                      </div>
                      <div>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.</div>
                      <div><br>
                      </div>
                      <div>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.</div>
                      <div><br>
                      </div>
                      <div>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.</div>
                      <div><br>
                      </div>
                      <div>Obviously, we'll need to figure out the API
                        and any other kind of problems with this
                        proposal.</div>
                      <div><br>
                      </div>
                      <div>What do you think? </div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div>Thanks,</div>
                      <div>Ram.</div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                    </div>
                  </div>
                </blockquote>
                <blockquote type="cite">
                  <div dir="ltr"><span>_______________________________________________</span><br>
                    <span>Python-ideas mailing list</span><br>
                    <span><a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a></span><br>
                    <span><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="noreferrer">https://mail.python.org/mailman/listinfo/python-ideas</a></span><br>
                    <span>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="noreferrer">http://python.org/psf/codeofconduct/</a></span><br>
                  </div>
                </blockquote>
              </div>
            </blockquote>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset class="m_-5459406463158614336mimeAttachmentHeader"></fieldset>
      <pre class="m_-5459406463158614336moz-quote-pre">_______________________________________________
Python-ideas mailing list
<a class="m_-5459406463158614336moz-txt-link-abbreviated" href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a>
<a class="m_-5459406463158614336moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="noreferrer">https://mail.python.org/mailman/listinfo/python-ideas</a>
Code of Conduct: <a class="m_-5459406463158614336moz-txt-link-freetext" href="http://python.org/psf/codeofconduct/" target="_blank" rel="noreferrer">http://python.org/psf/codeofconduct/</a>
</pre>
    </blockquote>
  </div>

_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div></div>