Python asyncore.ExitNow() Examples
The following are 30
code examples of asyncore.ExitNow().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
asyncore
, or try the search function
.
Example #1
Source File: recipe-577808.py From code with MIT License | 6 votes |
def call(self): """Call this scheduled function.""" assert not self.cancelled, "Already cancelled" try: try: self._target(*self._args, **self._kwargs) except (KeyboardInterrupt, SystemExit, asyncore.ExitNow): raise except: if self._errback is not None: self._errback() else: raise finally: if not self.cancelled: self.cancel()
Example #2
Source File: ftpserver.py From script-languages with MIT License | 6 votes |
def handle_error(self): """Called when an exception is raised and not otherwise handled.""" try: raise except (KeyboardInterrupt, SystemExit, asyncore.ExitNow): raise except socket.error, err: # fixes around various bugs: # - http://bugs.python.org/issue1736101 # - http://code.google.com/p/pyftpdlib/issues/detail?id=104 # - http://code.google.com/p/pyftpdlib/issues/detail?id=109 if err.args[0] in _DISCONNECTED: self.handle_close() return else: self.log_exception(self) error = str(err.args[1]) # an error could occur in case we fail reading / writing # from / to file (e.g. file system gets full)
Example #3
Source File: recipe-577808.py From code with MIT License | 6 votes |
def call(self): # call this scheduled function and reschedule it right after assert not self.cancelled, "Already cancelled" exc = False try: try: self._target(*self._args, **self._kwargs) except (KeyboardInterrupt, SystemExit, asyncore.ExitNow): exc = True raise except: if self._errback is not None: self._errback() else: exc = True raise finally: if not self.cancelled: if exc: self.cancel() else: self.timeout = time.time() + self._delay heapq.heappush(_tasks, self)
Example #4
Source File: ftpserver.py From script-languages with MIT License | 6 votes |
def call(self): """Call this scheduled function.""" assert not self.cancelled, "Already cancelled" exc = None try: try: self._target(*self._args, **self._kwargs) except (KeyboardInterrupt, SystemExit, asyncore.ExitNow): raise except Exception, exc: if self._errback is not None: self._errback() else: raise finally: self._post_call(exc)
Example #5
Source File: test_asyncore.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #6
Source File: test_asyncore.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: test_asyncore.py From ironpython3 with Apache License 2.0 | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #8
Source File: test_asyncore.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #9
Source File: recipe-577808.py From code with MIT License | 5 votes |
def _scheduler(): """Run the scheduled functions due to expire soonest (if any).""" now = time.time() while _tasks and now >= _tasks[0].timeout: call = heapq.heappop(_tasks) if call._repush: heapq.heappush(_tasks, call) call._repush = False continue try: call.call() except (KeyboardInterrupt, SystemExit, asyncore.ExitNow): raise except: print traceback.format_exc()
Example #10
Source File: recipe-577808.py From code with MIT License | 5 votes |
def close_all(map=None, ignore_all=False): """Close all scheduled functions and opened sockets.""" if map is None: map = asyncore.socket_map for x in map.values(): try: x.close() except OSError, x: if x[0] == errno.EBADF: pass elif not ignore_all: raise except (asyncore.ExitNow, KeyboardInterrupt, SystemExit): raise
Example #11
Source File: test_asyncore.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #12
Source File: test_asyncore.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #13
Source File: test_asyncore.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #14
Source File: test_asyncore.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: test_asyncore.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #16
Source File: test_asyncore.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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
Example #17
Source File: buffered_dispatcher.py From polysh with GNU General Public License v2.0 | 5 votes |
def dispatch_write(self, buf: bytes) -> bool: """Augment the buffer with stuff to write when possible""" self.write_buffer += buf if len(self.write_buffer) > self.MAX_BUFFER_SIZE: console_output('Buffer too big ({:d}) for {}\n'.format( len(self.write_buffer), str(self)).encode()) raise asyncore.ExitNow(1) return True
Example #18
Source File: control_commands.py From polysh with GNU General Public License v2.0 | 5 votes |
def do_quit(command: str) -> None: raise asyncore.ExitNow(0)
Example #19
Source File: remote_dispatcher.py From polysh with GNU General Public License v2.0 | 5 votes |
def log(msg: bytes) -> None: if options.log_file: fd = options.log_file.fileno() while msg: try: written = os.write(fd, msg) except OSError as e: print('Exception while writing log:', options.log_file.name) print(e) raise asyncore.ExitNow(1) msg = msg[written:]
Example #20
Source File: test_asyncore.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #21
Source File: test_asyncore.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #22
Source File: ftpserver.py From script-languages with MIT License | 5 votes |
def __call__(self): now = time.time() calls = [] while self._tasks: if now < self._tasks[0].timeout: break call = heapq.heappop(self._tasks) if not call.cancelled: calls.append(call) else: self._cancellations -= 1 for call in calls: if call._repush: heapq.heappush(self._tasks, call) call._repush = False continue try: call.call() except (KeyboardInterrupt, SystemExit, asyncore.ExitNow): raise except: logerror(traceback.format_exc()) # remove cancelled tasks and re-heapify the queue if the # number of cancelled tasks is more than the half of the # entire queue if self._cancellations > 512 \ and self._cancellations > (len(self._tasks) >> 1): self._cancellations = 0 self._tasks = [x for x in self._tasks if not x.cancelled] self.reheapify()
Example #23
Source File: test_asyncore.py From oss-ftp with MIT License | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #24
Source File: test_asyncore.py From oss-ftp with MIT License | 5 votes |
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
Example #25
Source File: test_asyncore.py From BinderFilter with MIT License | 5 votes |
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
Example #26
Source File: test_asyncore.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #27
Source File: backdoros.py From backdoros with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _do_REBOOT(self, params): raise asyncore.ExitNow('Server is rebooting!')
Example #28
Source File: test_asyncore.py From BinderFilter with MIT License | 5 votes |
def handle_read_event(self): raise asyncore.ExitNow()
Example #29
Source File: backdoros.py From backdoros with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _do_SHUTDOWN(self, params): global _is_alive _is_alive = False raise asyncore.ExitNow('Server is quitting!')
Example #30
Source File: ftpserver.py From script-languages with MIT License | 5 votes |
def handle_error(self): """Called to handle any uncaught exceptions.""" try: raise except (KeyboardInterrupt, SystemExit, asyncore.ExitNow): raise except: logerror(traceback.format_exc()) self.close()