def __init__(self, iterable, item_callback, done_callback, unwind_stack = True, pop_list = False):
assert not pop_list or isinstance(iterable, list), "iterable must be a list when using pop_list"
self.item_callback = item_callback
self.done_callback = done_callback if done_callback is not None else lambda: None
self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3]
self.unwind_stack = unwind_stack
self.pop_list = pop_list
try:
if self.pop_list:
self.iterator = iterable
else:
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
except Exception:
logger.debug("Problem constructing iterator for %s", repr(iterable))
raise
self.doit()
python类ExitNow()的实例源码
def __call__(self, *args, **kwargs):
def thunk():
try:
self.func(self.cb, self.eb, *args, **kwargs)
except ExitNow:
raise
except Exception, e:
self.eb(e)
event_defer(thunk)
if self.disable_signal_handlers:
event_loop(catch_signals = ())
else:
event_loop()
if not self.fin:
logger.warning("%r event_loop terminated without callback or errback", self)
if self.err is None:
return self.res
elif isinstance(self.err, tuple):
raise self.err[0], self.err[1], self.err[2]
else:
raise self.err
def __init__(self, iterable, item_callback, done_callback, unwind_stack = True, pop_list = False):
assert not pop_list or isinstance(iterable, list), "iterable must be a list when using pop_list"
self.item_callback = item_callback
self.done_callback = done_callback if done_callback is not None else lambda: None
self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3]
self.unwind_stack = unwind_stack
self.pop_list = pop_list
try:
if self.pop_list:
self.iterator = iterable
else:
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
except Exception:
logger.debug("Problem constructing iterator for %s", repr(iterable))
raise
self.doit()
def __call__(self, *args, **kwargs):
def thunk():
try:
self.func(self.cb, self.eb, *args, **kwargs)
except ExitNow:
raise
except Exception, e:
self.eb(e)
event_defer(thunk)
if self.disable_signal_handlers:
event_loop(catch_signals = ())
else:
event_loop()
if not self.fin:
logger.warning("%r event_loop terminated without callback or errback", self)
if self.err is None:
return self.res
elif isinstance(self.err, tuple):
raise self.err[0], self.err[1], self.err[2]
else:
raise self.err
def __init__(self, iterable, item_callback, done_callback, unwind_stack = True, pop_list = False):
assert not pop_list or isinstance(iterable, list), "iterable must be a list when using pop_list"
self.item_callback = item_callback
self.done_callback = done_callback if done_callback is not None else lambda: None
self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3]
self.unwind_stack = unwind_stack
self.pop_list = pop_list
try:
if self.pop_list:
self.iterator = iterable
else:
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
except Exception:
logger.debug("Problem constructing iterator for %s", repr(iterable))
raise
self.doit()
def __init__(self, iterable, item_callback, done_callback, unwind_stack = True, pop_list = False):
assert not pop_list or isinstance(iterable, list), "iterable must be a list when using pop_list"
self.item_callback = item_callback
self.done_callback = done_callback if done_callback is not None else lambda: None
self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3]
self.unwind_stack = unwind_stack
self.pop_list = pop_list
try:
if self.pop_list:
self.iterator = iterable
else:
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
except Exception:
logger.debug("Problem constructing iterator for %s", repr(iterable))
raise
self.doit()
def __call__(self, *args, **kwargs):
def thunk():
try:
self.func(self.cb, self.eb, *args, **kwargs)
except ExitNow:
raise
except Exception, e:
self.eb(e)
event_defer(thunk)
if self.disable_signal_handlers:
event_loop(catch_signals = ())
else:
event_loop()
if not self.fin:
logger.warning("%r event_loop terminated without callback or errback", self)
if self.err is None:
return self.res
elif isinstance(self.err, tuple):
raise self.err[0], self.err[1], self.err[2]
else:
raise self.err
def __init__(self, iterable, item_callback, done_callback, unwind_stack = True, pop_list = False):
assert not pop_list or isinstance(iterable, list), "iterable must be a list when using pop_list"
self.item_callback = item_callback
self.done_callback = done_callback if done_callback is not None else lambda: None
self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3]
self.unwind_stack = unwind_stack
self.pop_list = pop_list
try:
if self.pop_list:
self.iterator = iterable
else:
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
except Exception:
logger.debug("Problem constructing iterator for %s", repr(iterable))
raise
self.doit()
def __call__(self, *args, **kwargs):
def thunk():
try:
self.func(self.cb, self.eb, *args, **kwargs)
except ExitNow:
raise
except Exception, e:
self.eb(e)
event_defer(thunk)
if self.disable_signal_handlers:
event_loop(catch_signals = ())
else:
event_loop()
if not self.fin:
logger.warning("%r event_loop terminated without callback or errback", self)
if self.err is None:
return self.res
elif isinstance(self.err, tuple):
raise self.err[0], self.err[1], self.err[2]
else:
raise self.err
def __init__(self, iterable, item_callback, done_callback, unwind_stack = True, pop_list = False):
assert not pop_list or isinstance(iterable, list), "iterable must be a list when using pop_list"
self.item_callback = item_callback
self.done_callback = done_callback if done_callback is not None else lambda: None
self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3]
self.unwind_stack = unwind_stack
self.pop_list = pop_list
try:
if self.pop_list:
self.iterator = iterable
else:
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
except Exception:
logger.debug("Problem constructing iterator for %s", repr(iterable))
raise
self.doit()
def __init__(self, iterable, item_callback, done_callback, unwind_stack = True, pop_list = False):
assert not pop_list or isinstance(iterable, list), "iterable must be a list when using pop_list"
self.item_callback = item_callback
self.done_callback = done_callback if done_callback is not None else lambda: None
self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3]
self.unwind_stack = unwind_stack
self.pop_list = pop_list
try:
if self.pop_list:
self.iterator = iterable
else:
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
except Exception:
logger.debug("Problem constructing iterator for %s", repr(iterable))
raise
self.doit()
def __call__(self, *args, **kwargs):
def thunk():
try:
self.func(self.cb, self.eb, *args, **kwargs)
except ExitNow:
raise
except Exception, e:
self.eb(e)
event_defer(thunk)
if self.disable_signal_handlers:
event_loop(catch_signals = ())
else:
event_loop()
if not self.fin:
logger.warning("%r event_loop terminated without callback or errback", self)
if self.err is None:
return self.res
elif isinstance(self.err, tuple):
raise self.err[0], self.err[1], self.err[2]
else:
raise self.err
def handle_read_event(self):
raise asyncore.ExitNow()
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
def handle_read_event(self):
raise asyncore.ExitNow()
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
def handle_read_event(self):
raise asyncore.ExitNow()
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
def writable(self):
if not self.shd["loop"]:
raise asyncore.ExitNow('Connector is quitting!')
if not self.ciao_queue.empty() and not self.write_pending:
return True
return False
def handle_read_event(self):
raise asyncore.ExitNow()
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
def handle_read_event(self):
raise asyncore.ExitNow()
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
def handle_read_event(self):
raise asyncore.ExitNow()
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
def handle_read_event(self):
raise asyncore.ExitNow()
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
def runq(cls):
"""
Run the timer queue: for each timer whose call time has passed,
pull the timer off the queue and call its handler() method.
Comparisions are made against time at which this function was
called, so that even if new events keep getting scheduled, we'll
return to the I/O loop reasonably quickly.
"""
now = rpki.sundial.now()
while timer_queue and now >= timer_queue[0].when:
t = timer_queue.pop(0)
if cls.run_debug:
logger.debug("Running %r", t)
try:
if t.handler is not None:
t.handler()
else:
logger.warning("Timer %r expired with no handler set", t)
except (ExitNow, SystemExit):
raise
except Exception, e:
if t.errback is not None:
t.errback(e)
else:
logger.exception("Unhandled exception from timer %r", t)
def runq(cls):
"""
Run the timer queue: for each timer whose call time has passed,
pull the timer off the queue and call its handler() method.
Comparisions are made against time at which this function was
called, so that even if new events keep getting scheduled, we'll
return to the I/O loop reasonably quickly.
"""
now = rpki.sundial.now()
while timer_queue and now >= timer_queue[0].when:
t = timer_queue.pop(0)
if cls.run_debug:
logger.debug("Running %r", t)
try:
if t.handler is not None:
t.handler()
else:
logger.warning("Timer %r expired with no handler set", t)
except (ExitNow, SystemExit):
raise
except Exception, e:
if t.errback is not None:
t.errback(e)
else:
logger.exception("Unhandled exception from timer %r", t)
def runq(cls):
"""
Run the timer queue: for each timer whose call time has passed,
pull the timer off the queue and call its handler() method.
Comparisions are made against time at which this function was
called, so that even if new events keep getting scheduled, we'll
return to the I/O loop reasonably quickly.
"""
now = rpki.sundial.now()
while timer_queue and now >= timer_queue[0].when:
t = timer_queue.pop(0)
if cls.run_debug:
logger.debug("Running %r", t)
try:
if t.handler is not None:
t.handler()
else:
logger.warning("Timer %r expired with no handler set", t)
except (ExitNow, SystemExit):
raise
except Exception, e:
if t.errback is not None:
t.errback(e)
else:
logger.exception("Unhandled exception from timer %r", t)