<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi there,</div><div class="">I have glanced over your patch</div><div class="">I do not have a Windows box to try and repro these shutdown issues, so I might very well be missing some critical Windows-specific detail in my feedback</div><div class=""><br class=""></div><div class="">Release() seems to be a fairly dangerous accessor - indeed I am not positive that releasing without deallocation the session and modules dictionaries will do the right thing when Py_Finalize() is not involved</div><div class="">I might very well create an SBDebugger (which - via the command interpreter - owns the ScriptInterpreterPython); if I simply let go of the last reference to the SBDebugger, the destruction chain should do the right thing, and I expect your release-without-decref calls might cause some objects to survive their due lifetime</div><div class="">At the very least, would it be possible to wrap those releases in an if (Py_IsInitialized()) like you do in another change?</div><div class=""><br class=""></div><div class="">As for 3 - nothing in the Python documentation specifies that the atexit facility does not allow any “meaningful code” execution; the main caveat I could find online about it is that there are escape routes out of Python that atexit() does not handle - but that seems a very different concern from what you are seeing</div><div class="">Even if we actually end up deciding that atexit is not to be used, your patch as-is has eliminated the call to the code to delete crashinfo.so - that is not critical of course, but it worries me to see a duplication of lldb.SBDebugger.Terminate() calls - it might be more appropriate, if anything, to define a function</div><div class=""><br class=""></div><div class="">def exitFromTestSuite(exitCode = None):</div><div class=""> deleteCrashInfoDylib(dylib_dst)</div><div class=""> lldb.SBDebugger.Terminate()</div><div class=""> if exitCode != None:</div><div class="">    sys.exit(exitCode)</div><div class=""><br class=""></div><div class="">Then we would all know to put our atexit calls in exitFromTestSuite(), and we’d have some degree of confidence that all cleanup tasks will be executed on all ways out of the test suite.</div><div class="">But, again, I am not sure why atexit is giving you woes - that would probably be worth looking into</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 7, 2014, at 4:03 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">There were a number of issues related to python shutdown.  These issues appear to be present on every platform, but are benign except for Windows.  On Windows they present because Windows must build against a debug python interpreter, which asserts when these issues arise.  The issues, along with their respective fixes, are:<br class=""><br class="">1) decrementing the reference count of dead objects.  This happens because we store the session dictionary in the ScriptInterpreterPython class, and when these are destroyed on shutdown, they get decref'ed.  However, this happens during or after a Py_Finalize, so Python has already destroyed these objects.  The fix employed here is to add a Release() method to PythonObject() which simply drops the underlying object.<br class=""><br class="">2) Attempting to execute embedded python during Py_Finalize.  This results in error messages "NameError: module 'lldb' not found" after tests run.  The fix here is to only execute these commands if Py_IsInitialized()<br class=""><br class="">3) Use of sys.atexit().  atexit handlers are run as part of Py_Finalize, and at this point it is unspecified which, if any modules have been destroyed.  So no meaningful code can run here.  The fix employed here is to explicitly call lldb.SBDebugger.Terminate() before calling sys.exit().  A better fix would be to not use sys.exit() at all, but instead have a clean shutdown path, perhaps by way of raising an exception that is caught at the top-level of the python script.<br class=""><br class=""><a href="http://reviews.llvm.org/D4826" class="">http://reviews.llvm.org/D4826</a><br class=""><br class="">Files:<br class="">  include/lldb/Interpreter/PythonDataObjects.h<br class="">  source/Interpreter/ScriptInterpreterPython.cpp<br class="">  test/dotest.py<br class=""><span id="cid:49BD7F64-99E3-4C0A-88F2-8CF57D168307@apple.com"><D4826.12296.patch></span>_______________________________________________<br class="">lldb-commits mailing list<br class="">lldb-commits@cs.uiuc.edu<br class="">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits<br class=""></div></blockquote></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><i class="">- Enrico</i><br class="">📩 egranata@<font color="#ff2600" class=""></font>.com ☎️ 27683</div><div class=""><br class=""></div></div></div></div></div><br class="Apple-interchange-newline">
</div>
<br class=""></body></html>