473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

atexit, sys.exit, sys.exitfunc, reaching end of source code

Hi,

I am playing with the atexit module but I don't find a way to see the
difference
between a script calling sys.exit(<returncode>) and the interpreting
arriving at the end
of the source code file. This has a semantic difference for my
applications.
Is there a way to determine in an exithandler (that is registered
using atexit.register)
how I exited?

Second question: is there a way to determine in my exithandler what
the return code was.
atexit doesn't seem to support that

Third question: I can solve part of my problem by reassigning sys.exit
= myfunction
Is that a wise idea? It seems that an interpreter (python 2.4)
reaching end of source code, calls sys.exitfunc instead of sys.exit ?
Thanks

Carl D'Halluin

www.qlayer.com

Jul 11 '07 #1
3 3304
ca***********@gmail.com wrote:
I am playing with the atexit module but I don't find a way to see the
difference
between a script calling sys.exit(<returncode>) and the interpreting
arriving at the end
of the source code file. This has a semantic difference for my
applications.
Is there a way to determine in an exithandler (that is registered
using atexit.register)
how I exited?
Actually sys.exit raises exception SystemExit, but if interpreter
reaches end of script exception is not raised. Try something
like this:

if __name__ == '__main__':
exit_code_for_exithandler = None
try:
#...
sys.exit(5)
pass
#...
except SystemExit, e:
exit_code_for_exithandler = e.code
print "sys.exit called"
else:
print "end of script"

w.
Jul 11 '07 #2
On 12 jul, 01:32, Wojciech Mu a
<wojciech_m...@poczta.null.onet.pl.invalidwrote:
carl.dhall...@gmail.com wrote:
I am playing with theatexitmodule but I don't find a way to see the
difference
between a script calling sys.exit(<returncode>) and the interpreting
arriving at the end
of the source code file. This has a semantic difference for my
applications.
Is there a way to determine in an exithandler (that is registered
usingatexit.register)
how I exited?

Actually sys.exit raises exception SystemExit, but if interpreter
reaches end of script exception is not raised. Try something
like this:

if __name__ == '__main__':
exit_code_for_exithandler = None
try:
#...
sys.exit(5)
pass
#...
except SystemExit, e:
exit_code_for_exithandler = e.code
print "sys.exit called"
else:
print "end of script"

w.
I am getting quite confused with this SystemExit.
If I register a custom sys.excepthook then it is never invoked
when I do sys.exit(.)

Jul 12 '07 #3
En Thu, 12 Jul 2007 06:30:45 -0300, ca***********@gmail.com
<ca***********@gmail.comescribió:
I am getting quite confused with this SystemExit.
If I register a custom sys.excepthook then it is never invoked
when I do sys.exit(.)
No, sys.excepthook won't be called for SystemExit:

pyhelp(sys)
Help on built-in module sys:
[...]
excepthook -- called to handle any uncaught exception other than
SystemExit

Unfortunately help(sys.excepthook) does not provide the same information,
neither the docs for the sys module. (Should be corrected...)

--
Gabriel Genellina

Jul 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hameed Khan | last post by:
hi, i was reading the manual for sys module. i found a description for a function known as exitfunc. and it says the function installed by sys.exitfunc(cleanUpFunc) call will be called when the...
0
by: Bengt Richter | last post by:
Still looking for a unifying concept ;-) It struck me that @deco1 @deco2 def foo():pass uses '@' to register at-next-name-binding processing in a way similar to atexit's registering of...
3
by: Serve Laurijssen | last post by:
Does the C++ standard say whether destructors are called before or after "atexit" functions are called. Or is nothing said about that?
8
by: JKop | last post by:
Let's say that when your program ends (no matter how) that you want a certain block of code to be executed at the end. Here's the code: std::cout << "The program will now end.\n";...
2
by: Steve Lambert | last post by:
Hi, Is it possible for the functions registered with atexit() to have access to parameter to exit i.e EXIT_SUCCESS or EXIT_FAILURE? I'd like to register a set of routines to be executed on...
7
by: David Rushby | last post by:
Consider the following program (underscores are used to force indentation): ------------------------------------------------ import atexit, threading, time def atExitFunc(): ____print...
20
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static...
16
by: Laurent Deniau | last post by:
I would like to know if the use of the pointer ref in the function cleanup() below is valid or if something in the norm prevents this kind of cross-reference during exit(). I haven't seen anything...
2
by: Christopher Pisz | last post by:
I am attempting to write a "Phoenix Singleton" using the book "Modern C++ Design" by Alexandrescu I do not understand his use of... #ifndef ATEXIT_FIXED std::atexit(Kill); #endif ....in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.