From: Stefan R. <Ste...@gm...> - 2017-03-31 14:03:05
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div> <div>I just added a version of sys._current_frames that skips null-frames. See https://hg.python.org/jython/rev/b051f30c4cd4.</div> <div>So this will be in Jython 2.7.1. Feel free to test it from current trunk version.</div> <div> </div> <div>-Stefan</div> <div> </div> <div> <div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"> <div style="margin:0 0 10px 0;"><b>Gesendet:</b> Donnerstag, 30. März 2017 um 20:22 Uhr<br/> <b>Von:</b> "Fabio Zadrozny" <fa...@gm...><br/> <b>An:</b> "Stefan Richthofer" <Ste...@gm...><br/> <b>Cc:</b> "Jython Developers" <jyt...@li...><br/> <b>Betreff:</b> Re: [Jython-dev] Support for sys._current_frames</div> <div name="quoted-content"> <div> <div class="gmail_default" style="color: rgb(0,0,0);">Thank you all for the comments.</div> <div class="gmail_default" style="color: rgb(0,0,0);"> </div> <div class="gmail_default" style="color: rgb(0,0,0);">Given the sample code, I was able to implement a replacement in PyDev, in pure-Python, while Jython itself provides no sys._current_frames (given that it seems simple to implement, it'd be nice to have this in a Jython release sooner rather than later, as my implementation replacement has to access a private attribute -- which is different from the latest 2.7.0 in the downloads to the current development version -- and it'll probably stop working as Jython itself moves forward.</div> <div class="gmail_default" style="color: rgb(0,0,0);"> </div> <div class="gmail_default" style="color: rgb(0,0,0);">@Stefan: Regarding having None frames, I think that this shouldn't be allowed (not that I couldn't change PyDev to deal with it, but this is not the behavior CPython gives, so, I think the return should be protected to disallow None values -- there are other uses for sys._current_frames, for instance, on PyVmMonitor I use it to gather stack information, and I bet there are other uses out there which wouldn't protect from receiving a None there).</div> <div class="gmail_default" style="color: rgb(0,0,0);"> </div> <div class="gmail_default" style="color: rgb(0,0,0);">The pure-python replacement I'm using if sys._current_frames is not found is below (may also be seen at: <a href="https://github.com/fabioz/PyDev.Debugger/commit/a4a58179dab9f9fb93559066f0ef22ac59c59e04" target="_blank">https://github.com/fabioz/PyDev.Debugger/commit/a4a58179dab9f9fb93559066f0ef22ac59c59e04</a>).</div> <div class="gmail_default" style="color: rgb(0,0,0);"> </div> <div class="gmail_default" style="color: rgb(0,0,0);">Thanks,</div> <div class="gmail_default" style="color: rgb(0,0,0);"> </div> <div class="gmail_default" style="color: rgb(0,0,0);">Fabio</div> <div class="gmail_default" style="color: rgb(0,0,0);"> </div> <div class="gmail_default"> <div class="gmail_default"> <div class="gmail_default"><font color="#000000" face="monospace, monospace">from java.lang import NoSuchFieldException</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace">from org.python.core import ThreadStateMapping</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace">try:</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace">except NoSuchFieldException:</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace">cachedThreadState.accessible = True</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace">thread_states = cachedThreadState.get(ThreadStateMapping)</font></div> <div class="gmail_default"> </div> <div class="gmail_default"><font color="#000000" face="monospace, monospace">def _current_frames():</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> as_array = thread_states.entrySet().toArray()</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> ret = {}</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> for thread_to_state in as_array:</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> thread = thread_to_state.getKey()</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> if thread is None:</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> continue</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> thread_state = thread_to_state.getValue()</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> if thread_state is None:</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> continue</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> </font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> frame = thread_state.frame</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> if frame is None:</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> continue</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> </font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> ret[thread.getId()] = frame</font></div> <div class="gmail_default"><font color="#000000" face="monospace, monospace"> return ret</font></div> </div> <div style="color: rgb(0,0,0);"> </div> </div> </div> <div class="gmail_extra"> <div class="gmail_quote">On Wed, Mar 29, 2017 at 6:08 PM, Stefan Richthofer <span><<a href="mailto:Ste...@gm..." onclick="parent.window.location.href='Ste...@gm...'; return false;" target="_blank">Ste...@gm...</a>></span> wrote: <blockquote class="gmail_quote" style="margin: 0 0 0 0.8ex;border-left: 1.0px rgb(204,204,204) solid;padding-left: 1.0ex;"><span>> Your elements array should be twice as long, I think?</span><br/> Obviously it should ;)<br/> <br/> Agreed on all points. I just tested the implementation and observed that<br/> an entry in globalThreadStates yields a null-PyFrame. How should we deal<br/> with that?<br/> <br/> a) Is it a bug and we should investigate how it can be null and solve it?<br/> b) set the frame to None in result of _current_frames<br/> c) skip such elements and let _current_frames only return a reduced dict?<br/> <br/> @Fabio regarding b), would PyDev be robust against None-values here?<br/> <br/> Despite this, the result looks rather much like in CPython.<br/> <br/> <br/> > Gesendet: Mittwoch, 29. März 2017 um 22:04 Uhr<br/> > Von: "Jeff Allen" <<a href="mailto:ja...@fa..." onclick="parent.window.location.href='ja...@fa...'; return false;" target="_blank">ja...@fa...</a>><br/> > An: <a href="mailto:jyt...@li..." onclick="parent.window.location.href='jyt...@li...'; return false;" target="_blank">jyt...@li...</a><br/> > Betreff: Re: [Jython-dev] Support for sys._current_frames <div class="HOEnZb"> <div class="h5">><br/> > This seems to be a faithful equivalent to the CPython implementation.<br/> > That is wrapped in a synchronisation construct, but globalThreadStates<br/> > is of a thread-safe class, I see. However, as the number of threads<br/> > might change between the call to size() and the call to toArray(), I<br/> > think it would be better to let toArray() always allocate the array<br/> > (i.e. give it a zero-length prototype).<br/> ><br/> > Your elements array should be twice as long, I think?<br/> ><br/> > The way we manage ThreadState and interpreters leaves me uneasy, but<br/> > that's not a criticism against this proposal, except for the risk of<br/> > change when the penny finally drops.<br/> ><br/> > Oh, and thanks to Fabio for continuing to support Jython in PyDev.<br/> ><br/> > Jeff Allen<br/> ><br/> > On 29/03/2017 17:30, Stefan Richthofer wrote:<br/> > > I suggest this could be implemented in ThreadStateMapping like this:<br/> > > (on top of that an implementation in PySystemState is straight forward)<br/> > > public static PyObject _current_frames() {<br/> > > @SuppressWarnings("unchecked")<br/> > > Map.Entry<Thread, ThreadState>[] entries = new<br/> > > Map.Entry[globalThreadStates.size()];<br/> > > entries = globalThreadStates.entrySet().toArray(entries);<br/> > > PyObject elements[] = new PyObject[entries.length];<br/> > > int pos = 0;<br/> > > for (Map.Entry<Thread, ThreadState> entry: entries) {<br/> > > elements[pos++] = Py.newInteger(entry.getKey().getId());<br/> > > elements[pos++] = entry.getValue().frame;<br/> > > }<br/> > > return new PyDictionary(elements);<br/> > > }<br/> > > Opinions?<br/> > > -Stefan<br/> > > *Gesendet:* Mittwoch, 29. März 2017 um 17:30 Uhr<br/> > > *Von:* "Fabio Zadrozny" <<a href="mailto:fa...@gm..." onclick="parent.window.location.href='fa...@gm...'; return false;" target="_blank">fa...@gm...</a>><br/> > > *An:* "Jython Developers" <<a href="mailto:jyt...@li..." onclick="parent.window.location.href='jyt...@li...'; return false;" target="_blank">jyt...@li...</a>><br/> > > *Betreff:* [Jython-dev] Support for sys._current_frames<br/> > > Hi Jython devs,<br/> > > I've just updated the PyDev debugger to drop support for older Python<br/> > > versions and it seems I ended up breaking debugging in the current<br/> > > Jython version because of it...<br/> > > The issue is that PyDev now requires sys._current_frames to be<br/> > > implemented by the interpreter (available since Python 2.5), but it<br/> > > seems this is not available for Jython -- this is needed so that the<br/> > > debugger can be faster (i.e.: it runs with untraced frames until some<br/> > > breakpoint is actually added -- at that point it gets the current<br/> > > frames and sets the tracing in them).<br/> > > So, I'd like to check how feasible it'd be to have this support in Jython.<br/> > > Thanks,<br/> > > Fabio<br/> > > ------------------------------------------------------------------------------<br/> > > Check out the vibrant tech community on one of the world's most<br/> > > engaging tech sites, Slashdot.org!<br/> > > <a href="http://sdm.link/slashdot_______________________________________________" target="_blank">http://sdm.link/slashdot_______________________________________________</a><br/> > > Jython-dev mailing list <a href="mailto:Jyt...@li..." onclick="parent.window.location.href='Jyt...@li...'; return false;" target="_blank">Jyt...@li...</a><br/> > > <a href="https://lists.sourceforge.net/lists/listinfo/jython-dev" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-dev</a><br/> > ><br/> > ><br/> > > ------------------------------------------------------------------------------<br/> > > Check out the vibrant tech community on one of the world's most<br/> > > engaging tech sites, Slashdot.org! <a href="http://sdm.link/slashdot" target="_blank">http://sdm.link/slashdot</a><br/> > ><br/> > ><br/> > > _______________________________________________<br/> > > Jython-dev mailing list<br/> > > <a href="mailto:Jyt...@li..." onclick="parent.window.location.href='Jyt...@li...'; return false;" target="_blank">Jyt...@li...</a><br/> > > <a href="https://lists.sourceforge.net/lists/listinfo/jython-dev" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-dev</a><br/> ><br/> ><br/> > ------------------------------------------------------------------------------<br/> > Check out the vibrant tech community on one of the world's most<br/> > engaging tech sites, Slashdot.org! <a href="http://sdm.link/slashdot" target="_blank">http://sdm.link/slashdot</a><br/> > _______________________________________________<br/> > Jython-dev mailing list<br/> > <a href="mailto:Jyt...@li..." onclick="parent.window.location.href='Jyt...@li...'; return false;" target="_blank">Jyt...@li...</a><br/> > <a href="https://lists.sourceforge.net/lists/listinfo/jython-dev" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-dev</a><br/> ><br/> <br/> ------------------------------------------------------------------------------<br/> Check out the vibrant tech community on one of the world's most<br/> engaging tech sites, Slashdot.org! <a href="http://sdm.link/slashdot" target="_blank">http://sdm.link/slashdot</a><br/> _______________________________________________<br/> Jython-dev mailing list<br/> <a href="mailto:Jyt...@li..." onclick="parent.window.location.href='Jyt...@li...'; return false;" target="_blank">Jyt...@li...</a><br/> <a href="https://lists.sourceforge.net/lists/listinfo/jython-dev" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-dev</a></div> </div> </blockquote> </div> </div> ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! <a href="http://sdm.link/slashdot_______________________________________________" target="_blank">http://sdm.link/slashdot_______________________________________________</a> Jython-dev mailing list Jyt...@li... <a href="https://lists.sourceforge.net/lists/listinfo/jython-dev" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-dev</a></div> </div> </div> </div></div></body></html> |