You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ;).
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!
collinwinter commented on Mar 15, 2007
collinwintermannequin
Mannequin
More actions
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
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...
collinwinter commented on Mar 15, 2007
collinwintermannequin
Mannequin
More actions
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.
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)
collinwinter commented on Mar 15, 2007
collinwintermannequin
Mannequin
More actions
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?
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...)
collinwinter commented on Mar 15, 2007
collinwintermannequin
Mannequin
More actions
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
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.
collinwinter commented on Mar 15, 2007
collinwintermannequin
Mannequin
More actions
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?
Current AtExit handlers are not likely to use functionality not in their domain, though.
The socket one just cleans up the socket API, the Tkinter one (which is disabled though) cleans up Tcl, etc.
I thought call_ll_exitfuncs() is already LIFO.
collinwinter commented on Mar 15, 2007
collinwintermannequin
Mannequin
More actions
It is LIFO; I was going off memory, sorry.
Is your assumption that atexit.py handlers will be more likely to use functionality outside their domain than would Py_AtExit handlers?
It's not specified that exit handlers can do cleanup only, in theory they could do things like sending an email etc.
Please let's not introduce gratuitous breakage here.
collinwinter commented on Mar 16, 2007
collinwintermannequin
Mannequin
More actions
Ok, I'm sold on the two-phase atexit structure. I've updated my patch to keep atexit's handlers separate from the call_ll_exitfuncs() handlers.
File Added: atexit.patch
Activity
birkenfeld commentedon Mar 14, 2007
This removes sys.exitfunc. atexit is rewritten in C and uses as much of the existing sys.exitfunc-infrastructure (which is renamed).
alanmcintyre commentedon Mar 14, 2007
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 ;).
birkenfeld commentedon Mar 14, 2007
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!
collinwinter commentedon Mar 15, 2007
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
birkenfeld commentedon Mar 15, 2007
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...
collinwinter commentedon Mar 15, 2007
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.
birkenfeld commentedon Mar 15, 2007
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)
collinwinter commentedon Mar 15, 2007
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?
birkenfeld commentedon Mar 15, 2007
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...)
collinwinter commentedon Mar 15, 2007
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
birkenfeld commentedon Mar 15, 2007
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.
collinwinter commentedon Mar 15, 2007
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?
birkenfeld commentedon Mar 15, 2007
Current AtExit handlers are not likely to use functionality not in their domain, though.
The socket one just cleans up the socket API, the Tkinter one (which is disabled though) cleans up Tcl, etc.
I thought call_ll_exitfuncs() is already LIFO.
collinwinter commentedon Mar 15, 2007
It is LIFO; I was going off memory, sorry.
Is your assumption that atexit.py handlers will be more likely to use functionality outside their domain than would Py_AtExit handlers?
birkenfeld commentedon Mar 16, 2007
It's not specified that exit handlers can do cleanup only, in theory they could do things like sending an email etc.
Please let's not introduce gratuitous breakage here.
collinwinter commentedon Mar 16, 2007
Ok, I'm sold on the two-phase atexit structure. I've updated my patch to keep atexit's handlers separate from the call_ll_exitfuncs() handlers.
File Added: atexit.patch
birkenfeld commentedon Mar 17, 2007
Looks good, four points:
collinwinter commentedon Mar 18, 2007
birkenfeld commentedon Mar 19, 2007
You didn't attach a patch, but if you do these modification, you can check it in directly IMO.
collinwinter commentedon Mar 21, 2007
Checked in as r54472.
pitrou commentedon Aug 18, 2013
Sorry to ping you on an old issue, but can any of you explain why it was necessary to rewrite atexit in C?