Exemplo n.º 1
0
Arquivo: gen.py Projeto: yetone/hurray
 def error_callback(future):
     try:
         future.result()
     except Exception as e:
         if not isinstance(e, quiet_exceptions):
             app_log.error("Exception in Future %r after timeout",
                           future,
                           exc_info=True)
Exemplo n.º 2
0
        def __del__(self):
            if not self._log_traceback:
                # set_exception() was not called, or result() or exception()
                # has consumed the exception
                return

            tb = traceback.format_exception(*self._exc_info)

            app_log.error('Future %r exception was never retrieved: %s', self,
                          ''.join(tb).rstrip())
Exemplo n.º 3
0
    def handle_callback_exception(self, callback):
        """This method is called whenever a callback run by the `IOLoop`
        throws an exception.

        By default simply logs the exception as an error.  Subclasses
        may override this method to customize reporting of exceptions.

        The exception itself is not passed explicitly, but is available
        in `sys.exc_info`.
        """
        app_log.error("Exception in callback %r", callback, exc_info=True)
Exemplo n.º 4
0
def main():
    options.parse_command_line()

    if len(sys.argv) == 1:
        app_log.warning(
            "Warning: no config file specified, using the default config. "
            "In order to specify a config file use "
            "'hurray --config=/path/to/hurray.conf'")

    # check if base directory exists and is writable (TODO)
    absbase = os.path.abspath(os.path.expanduser(options.base))
    if not os.access(absbase, os.W_OK):
        app_log.error(
            "base directory {} does not exist or is not writable!".format(
                absbase))
        sys.exit(1)

    SWMR_SYNC.set_strategy(options.locking)

    server = HurrayServer(workers=options.workers)

    sockets = []

    if options.port != 0:
        sockets = bind_sockets(options.port, options.host)
        app_log.info("Listening on %s:%d", options.host, options.port)

    if options.socket:
        socket_file = os.path.abspath(os.path.expanduser(options.socket))
        app_log.info("Listening on {}".format(socket_file))
        sockets.append(bind_unix_socket(socket_file))

    if len(sockets) < 1:
        app_log.error('Define a socket and/or a port > 0')
        return

    signal.signal(signal.SIGTERM, partial(sig_handler, server))
    signal.signal(signal.SIGINT, partial(sig_handler, server))

    # Note that it does not make much sense to start >1 (master) processes
    # because they implement an async event loop that creates worker processes
    # itself.
    server.start(options.processes)

    # deregister the multiprocessing exit handler for the forked children.
    # Otherwise they try to join the shared (parent) process manager
    # SWMRSyncManager.
    import atexit
    atexit.unregister(_exit_function)

    server.add_sockets(sockets)
    IOLoop.current().start()
Exemplo n.º 5
0
 def _handle_connection(self, connection, address):
     if self.ssl_options is not None:
         assert ssl, "Python 2.6+ and OpenSSL required for SSL"
         try:
             connection = ssl_wrap_socket(connection,
                                          self.ssl_options,
                                          server_side=True,
                                          do_handshake_on_connect=False)
         except ssl.SSLError as err:
             if err.args[0] == ssl.SSL_ERROR_EOF:
                 return connection.close()
             else:
                 raise
         except socket.error as err:
             # If the connection is closed immediately after it is created
             # (as in a port scan), we can get one of several errors.
             # wrap_socket makes an internal call to getpeername,
             # which may return either EINVAL (Mac OS X) or ENOTCONN
             # (Linux).  If it returns ENOTCONN, this error is
             # silently swallowed by the ssl module, so we need to
             # catch another error later on (AttributeError in
             # SSLIOStream._do_ssl_handshake).
             # To test this behavior, try nmap with the -sT flag.
             # https://github.com/tornadoweb/tornado/pull/750
             if errno_from_exception(err) in (errno.ECONNABORTED,
                                              errno.EINVAL):
                 return connection.close()
             else:
                 raise
     try:
         if self.ssl_options is not None:
             stream = SSLIOStream(connection,
                                  io_loop=self.io_loop,
                                  max_buffer_size=self.max_buffer_size,
                                  read_chunk_size=self.read_chunk_size)
         else:
             stream = IOStream(connection,
                               io_loop=self.io_loop,
                               max_buffer_size=self.max_buffer_size,
                               read_chunk_size=self.read_chunk_size)
         future = self.handle_stream(stream, address)
         if future is not None:
             self.io_loop.add_future(future, lambda f: f.result())
     except Exception:
         app_log.error("Error in connection callback", exc_info=True)
Exemplo n.º 6
0
Arquivo: gen.py Projeto: yetone/hurray
 def callback(f):
     unfinished_children.remove(f)
     if not unfinished_children:
         result_list = []
         for f in children:
             try:
                 result_list.append(f.result())
             except Exception as e:
                 if future.done():
                     if not isinstance(e, quiet_exceptions):
                         app_log.error("Multiple exceptions in yield list",
                                       exc_info=True)
                 else:
                     future.set_exc_info(sys.exc_info())
         if not future.done():
             if keys is not None:
                 future.set_result(dict(zip(keys, result_list)))
             else:
                 future.set_result(result_list)
Exemplo n.º 7
0
Arquivo: gen.py Projeto: yetone/hurray
 def get_result(self):
     result_list = []
     exc_info = None
     for f in self.children:
         try:
             result_list.append(f.get_result())
         except Exception as e:
             if exc_info is None:
                 exc_info = sys.exc_info()
             else:
                 if not isinstance(e, self.quiet_exceptions):
                     app_log.error("Multiple exceptions in yield list",
                                   exc_info=True)
     if exc_info is not None:
         raise_exc_info(exc_info)
     if self.keys is not None:
         return dict(zip(self.keys, result_list))
     else:
         return list(result_list)
Exemplo n.º 8
0
def main():
    options.parse_command_line()
    server = HurrayServer()

    sockets = []

    if options.port != 0:
        sockets = bind_sockets(options.port, options.host)
        app_log.info("Listening on %s:%d", options.host, options.port)

    if options.socket:
        app_log.info("Listening on %s", options.socket)
        sockets.append(bind_unix_socket(options.socket))

    if len(sockets) < 1:
        app_log.error('Define a socket and/or a port > 0')
        return

    server.start(options.processes)
    server.add_sockets(sockets)
    IOLoop.current().start()
Exemplo n.º 9
0
 def __del__(self):
     if self.formatted_tb:
         app_log.error('Future exception was never retrieved: %s',
                       ''.join(self.formatted_tb).rstrip())