what does a python process return code -9 mean?

The script was killed by the operating system. Negative return values are the signal number which was used to kill the process. The script needed too much memory. I found this in syslog: Out of memory: Kill process 26184 (python) score 439 or sacrifice child Killed process 26184 (python) total-vm:628772kB, anon-rss:447660kB, file-rss:0kB

Graceful shutdown of a node.JS HTTP server

You can control the idle timeout for a connection, so you can set how long a keep-alive connection will remain open. For example: server=require(‘http’).createServer(function(req,res) { //Respond if(req.url.match(/^\/end.*/)) { server.close(); res.writeHead(200,{‘Content-Type’:’text/plain’}); res.end(‘Closedown’); } else { res.writeHead(200,{‘Content-Type’:’text/plain’}); res.end(‘Hello World!’); } }).listen(1088); //Set the idle timeout on any new connection server.addListener(“connection”,function(stream) { stream.setTimeout(4000); }); We can test this … Read more

python sys.exit not working in try [duplicate]

sys.exit() raises an exception, namely SystemExit. That’s why you land in the except-block. See this example: import sys try: sys.exit() except: print(sys.exc_info()[0]) This gives you: <type ‘exceptions.SystemExit’> Although I can’t imagine that one has any practical reason to do so, you can use this construct: import sys try: sys.exit() # this always raises SystemExit except … Read more

How to run one last function before getting killed in Python?

import time try: time.sleep(10) finally: print “clean up” clean up Traceback (most recent call last): File “<stdin>”, line 2, in <module> KeyboardInterrupt If you need to catch other OS level interrupts, look at the signal module: http://docs.python.org/library/signal.html Signal Example from signal import * import sys, time def clean(*args): print “clean me” sys.exit(0) for sig in … Read more

Generic way to exit a .NET application

Read this about the difference between using Environment and Application : Application.Exit Vs Environment.Exit There’s an example of what you want to do in the bottom of that page: if (System.Windows.Forms.Application.MessageLoop) { // Use this since we are a WinForms app System.Windows.Forms.Application.Exit(); } else { // Use this since we are a console app System.Environment.Exit(1); … Read more

How do I make a C++ console program exit?

While you can call exit() (and may need to do so if your application encounters some fatal error), the cleanest way to exit a program is to return from main(): int main() { // do whatever your program does } // function returns and exits program When you call exit(), objects with automatic storage duration … Read more

Bash trap on exit from function

Yes, you can trap RETURN : $ function foo() { > trap “echo finished” RETURN > echo “doing some things” > } $ foo Will display doing some things finished From man bash‘s description of the trap builtin : If a sigspec is RETURN, the command arg is executed each time a shell function or … Read more