Here are the examples of the python api sys._exit taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: concurrence Source File: core.py
def _dispatch(f = None):
"""The main dispatch routine. This is the starting point of any Concurrence program.
The dispatcher schedules tasklets until the :func:`quit` function is called or a SIGINT signal is received.
As a convenience a callable *f* can be provided that will be run in a new Tasklet."""
#first install signal handler
#this way we can quit the program easily from the command line
#also, this makes libevent block on the first loop
#otherwise when there are no events in the beginning, loop will not
#block and our main dispatch loop would claim 100% CPU time
def interrupt():
quit(EXIT_CODE_SIGINT)
event_interrupt = SignalEvent(SIGINT, interrupt)
#the heartbeat makes sure the main loop below at least
#makes a cycle every second. otherwise, if there are no pending signals
#libevent._loop would block indefinitly, causing our loop never to check
#if it still must be _running...
event_heartbeat = TimeoutEvent(1.0, None, True)
if callable(f):
Tasklet.new(f)()
global _running
_running = True
try:
#this is it, the main dispatch loop...
#tasklets are scheduled to run by stackless,
#and if no more are runnable, we wait for IO events to happen
#that will trigger tasks to become runnable
#ad infinitum...
while _running:
try:
while stackless.getruncount() > 1:
stackless.schedule()
except TaskletExit:
pass
except:
logging.exception("unhandled exception in dispatch schedule")
#note that we changed the way pyevent notifies us of pending events
#instead of calling the callbacks from within the pyevent extension
#it returns the list of callbacks that have to be called.
#calling from pyevent would give us a C stack which is not
#optimal (stackless would hardswitch instead of softswitch)
triggered = _event.loop()
while triggered:
callback, evtype = triggered.popleft()
try:
callback(evtype)
except TaskletExit:
raise
except:
logging.exception("unhandled exception in dispatch event callback")
finally:
event_interrupt.close()
event_heartbeat.close()
if DEBUG_LEAK:
logging.warn("alive objects:")
gc.collect()
_print_objects(gc.get_objects())
logging.warn('garbage:')
_print_objects(gc.garbage)
sys._exit(_exitcode)