original_docstring: Server that provides sockets to `callback`.
  
      Method must be invoked when cwd is suitable for secure creation of files.
  
      Args:
          callback: the callback function invoked on each request
          server_idle_timeout: timeout after which the server will stop
              automatically
          done: callback function invoked after setup and before we start handling
              requests
      
docstring: Server that provides sockets to `callback`.
  Method must be invoked when cwd is suitable for secure creation of files.
docstring_tokens: Server that provides sockets to ` callback ` . Method must be invoked when cwd is suitable for secure creation of files .
code: def _run_server(
      callback, server_idle_timeout: Optional[float], user_data, done
  ) -> None:
      """Server that provides sockets to `callback`.
  
      Method must be invoked when cwd is suitable for secure creation of files.
  
      Args:
          callback: the callback function invoked on each request
          server_idle_timeout: timeout after which the server will stop
              automatically
          done: callback function invoked after setup and before we start handling
              requests
      """
      logger.debug("_run_server()")
  
      loop = asyncio.new_event_loop()
  
      def print_exception(_loop, context):
          exc = context.get("exception")
          if exc:
              formatted_exc = "".join(
                  traceback.format_exception(type(exc), exc, exc.__traceback__)
              )
          else:
              formatted_exc = "<no exception>"
          logger.error("Error in event loop: %r\n%s", context, formatted_exc)
  
      loop.set_exception_handler(print_exception)
  
      handler = ProcessConnectionHandler(callback, {}, loop=loop)
  
      def finish_loop():
          logger.debug("Stopping loop")
          loop.stop()
          tasks = asyncio.all_tasks(loop)
          logger.debug("Number of pending tasks: %d", len(tasks))
          loop.run_until_complete(asyncio.gather(*tasks))
          logger.debug("Finished pending tasks")
  
      # socket_name is relative and we must already have cwd set to the
      # runtime_dir.
      server = Server(
          socket_name,
          stop_socket_name,
          handler,
          finish_loop,
          server_idle_timeout,
          loop=loop,
      )
  
      def handle_sigterm():
          logger.debug("Received SIGTERM")
          loop.create_task(server.stop())
  
      loop.add_signal_handler(signal.SIGTERM, handle_sigterm)
  
      done()
  
      # For logging.
      multiprocessing.current_process().name = "server"
  
      # For server state info.
      pid = os.getpid()
      server_state = {
          "create_time": time.time(),
          "lib_version": __version__,
          "idle_timeout": server_idle_timeout,
          "pid": pid,
          "user_data": user_data,
          "groups": os.getgroups(),
          "gid": os.getgid(),
      }
  
      with open(server_state_name, "w", encoding="utf-8") as f:
          json.dump(server_state, f)
  
      logger.debug("Starting server")
      server.serve()
  
      loop.run_forever()
      logger.debug("Server finished.")
code_tokens: def _run_server ( callback , server_idle_timeout : Optional [ float ] , user_data , done ) -> None : logger . debug ( "_run_server()" ) loop = asyncio . new_event_loop ( ) def print_exception ( _loop , context ) : exc = context . get ( "exception" ) if exc : formatted_exc = "" . join ( traceback . format_exception ( type ( exc ) , exc , exc . __traceback__ ) ) else : formatted_exc = "<no exception>" logger . error ( "Error in event loop: %r\n%s" , context , formatted_exc ) loop . set_exception_handler ( print_exception ) handler = ProcessConnectionHandler ( callback , { } , loop = loop ) def finish_loop ( ) : logger . debug ( "Stopping loop" ) loop . stop ( ) tasks = asyncio . all_tasks ( loop ) logger . debug ( "Number of pending tasks: %d" , len ( tasks ) ) loop . run_until_complete ( asyncio . gather ( * tasks ) ) logger . debug ( "Finished pending tasks" ) server = Server ( socket_name , stop_socket_name , handler , finish_loop , server_idle_timeout , loop = loop , ) def handle_sigterm ( ) : logger . debug ( "Received SIGTERM" ) loop . create_task ( server . stop ( ) ) loop . add_signal_handler ( signal . SIGTERM , handle_sigterm ) done ( ) multiprocessing . current_process ( ) . name = "server" pid = os . getpid ( ) server_state = { "create_time" : time . time ( ) , "lib_version" : __version__ , "idle_timeout" : server_idle_timeout , "pid" : pid , "user_data" : user_data , "groups" : os . getgroups ( ) , "gid" : os . getgid ( ) , } with open ( server_state_name , "w" , encoding = "utf-8" ) as f : json . dump ( server_state , f ) logger . debug ( "Starting server" ) server . serve ( ) loop . run_forever ( ) logger . debug ( "Server finished." )
short_docstring: Server that provides sockets to `callback`.
short_docstring_tokens: Server that provides sockets to ` callback ` .
comment: """Server that provides sockets to `callback`.
  
      Method must be invoked when cwd is suitable for secure creation of files.
  
      Args:
          callback: the callback function invoked on each request
          server_idle_timeout: timeout after which the server will stop
              automatically
          done: callback function invoked after setup and before we start handling
              requests
      """$SEP$# socket_name is relative and we must already have cwd set to the$SEP$# runtime_dir.$SEP$# For logging.$SEP$# For server state info.