Patches item #1680961, was opened at 2007-03-14 15:51 Message generated for change (Comment added) made by collinwinter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1680961&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core (C code) Group: Python 3000 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Georg Brandl (gbrandl) Assigned to: Nobody/Anonymous (nobody) Summary: remove sys.exitfunc, rewrite atexit in C Initial Comment: This removes sys.exitfunc. atexit is rewritten in C and uses as much of the existing sys.exitfunc-infrastructure (which is renamed). ---------------------------------------------------------------------- >Comment By: Collin Winter (collinwinter) Date: 2007-03-15 17:27 Message: Logged In: YES user_id=1344176 Originator: NO Doesn't that problem already exist, though, for C extensions that need sockets (or other resources) in their Py_AtExit handlers? Would changing call_ll_exitfuncs() from FIFO to LIFO (like atexit is) help this? ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2007-03-15 17:14 Message: Logged In: YES user_id=849994 Originator: YES For example, Modules/socketmodule.c's Py_AtExit handler, for Windows, calls WSACleanup(), after which, if I understand the docs correctly, one can't use sockets anymore. That would mean that if atexit is imported before socket, all atexit-registered exitfuncs cannot use sockets. ---------------------------------------------------------------------- Comment By: Collin Winter (collinwinter) Date: 2007-03-15 16:38 Message: Logged In: YES user_id=1344176 Originator: NO Isn't that (unavailable resources) a problem with atexit handlers in general, regardless of where they occur in Py_Finalize()? All existing low-level exitfuncs are already guaranteed not to mess with interpreter/thread state, simply because they can't (as things stand). If exitfuncs written against 3.0+ start messing around with Python's internal state, that's a bug in the exitfunc. We're all adults, etc. I'm attaching the new version of my patch, which includes atexit.unregister(). File Added: atexit.patch ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2007-03-15 14:01 Message: Logged In: YES user_id=849994 Originator: YES Yes, that would work for me. The issue I see with moving the low-level exitfuncs that is that the functions registered there may make resources unavailable that are necessary for Python code to run (and of course, atexit handlers can run arbitrary Python code...) ---------------------------------------------------------------------- Comment By: Collin Winter (collinwinter) Date: 2007-03-15 13:22 Message: Logged In: YES user_id=1344176 Originator: NO Googling turns up that the main use of atexit._exithandlers is to a) unregister a callback or b) clear all callbacks. I've already provided a _clear() function to handle (b), and an unregister() to deal with (a) shouldn't be hard. Thoughts? ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2007-03-15 13:00 Message: Logged In: YES user_id=849994 Originator: YES What about a function to get a *copy* of the exitfuncs? (Okay, I can't see a use case right now, but maybe it helps transitioning code that inspected atexit._exithandlers before) ---------------------------------------------------------------------- Comment By: Collin Winter (collinwinter) Date: 2007-03-15 12:49 Message: Logged In: YES user_id=1344176 Originator: NO Another difference: mine uses Py_AtExit(), yours adds extra C functions like Py_SetPythonExitfunc() and call_python_exitfunc(). I'd vote against exposing the handler list to Python code. I see that leading to "run my handler first! No, mine! *scuffle*" games. ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2007-03-15 03:28 Message: Logged In: YES user_id=849994 Originator: YES To summarize the differences: your code uses a C array to store the exit handlers, mine uses a Python list. Which to choose obviously depends on whether you want to make the list available to Python code... ---------------------------------------------------------------------- Comment By: Collin Winter (collinwinter) Date: 2007-03-15 02:11 Message: Logged In: YES user_id=1344176 Originator: NO Ack, I didn't know you were working on this, too! I'm attaching my own atexit implementation; the patch includes changes to Modules/Setup, test_atexit and test___all__ so that the test suite passes. One thing I'm not sure about is that I've moved call_ll_exitfuncs() up in the order of Py_Finalize(). This was necessary to make PyThreadState_GET() stop complaining about "no current thread" when calling the atexit functions at interpreter-shutdown, but I don't know enough to be sure that this change doesn't alter some assumption about finalization order. It looks alright to me, and "make test" passes, but I'd appreciate it if someone could look over that part. File Added: atexit.patch ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2007-03-14 18:30 Message: Logged In: YES user_id=849994 Originator: YES Note that the patch is against the p3yk branch. Note also that, without changing Modules/Setup, the new module won't be built and used. In fact, the test suite doesn't pass with it since I haven't updated the tests that depend on atexit._exithandlers. But thanks for reviewing nonetheless! ---------------------------------------------------------------------- Comment By: Alan McIntyre (alanmcintyre) Date: 2007-03-14 17:30 Message: Logged In: YES user_id=1115903 Originator: NO The attached patch didn't apply cleanly for me; the hunk that removes call_sys_exitfunc (pythonrun.c) failed, but everything else applied just fine. I removed call_sys_exitfunc manually and then everything compiled and passes regrtest.py (with -r -u all) with no unexpected skips (Linux). The docs also build just fine and I don't see any grammatical/formatting errors or anything that jumps out as a technical error (but I'm not all that familiar with atexit/exitfunc, so take my endorsement with a grain of salt ;). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1680961&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches