[Patches] [ python-Patches-1680961 ] remove sys.exitfunc, rewrite atexit in C

SourceForge.net noreply at sourceforge.net
Thu Mar 15 19:01:40 CET 2007


Patches item #1680961, was opened at 2007-03-14 19:51
Message generated for change (Comment added) made by gbrandl
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: Georg Brandl (gbrandl)
Date: 2007-03-15 18: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 17: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 17: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 16: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 07: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 06: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 22: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 21: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


More information about the Patches mailing list