docstr: Make sure that a fork server is running.
  
  This can be called from any process.  Note that usually a child
  process will just reuse the forkserver started by its parent, so
  ensure_running() will do nothing.
docstr_tok: ["Make","sure","that","a","fork","server","is","running",".","This","can","be","called","from","any","process",".","Note","that","usually","a","child","process","will","just","reuse","the","forkserver","started","by","its","parent",",","so","ensure_running","(",")","will","do","nothing","."]
code: def ensure_running(self):
      """Make sure that a fork server is running.
  
      This can be called from any process.  Note that usually a child
      process will just reuse the forkserver started by its parent, so
      ensure_running() will do nothing.
      """
      with self._lock:
          resource_tracker.ensure_running()
          if self._forkserver_pid is not None:
              # forkserver was launched before, is it still running?
              pid, status = os.waitpid(self._forkserver_pid, os.WNOHANG)
              if not pid:
                  # still alive
                  return
              # dead, launch it again
              os.close(self._forkserver_alive_fd)
              self._forkserver_address = None
              self._forkserver_alive_fd = None
              self._forkserver_pid = None
  
          cmd = (
              "from multiprocess.forkserver import main; "
              + "main(%d, %d, %r, **%r)"
          )
  
          if self._preload_modules:
              desired_keys = {"main_path", "sys_path"}
              data = spawn.get_preparation_data("ignore")
              data = {
                  x: y for x, y in data.items() if x in desired_keys
              }
          else:
              data = {}
  
          with socket.socket(socket.AF_UNIX) as listener:
              address = connection.arbitrary_address("AF_UNIX")
              listener.bind(address)
              if not util.is_abstract_socket_namespace(address):
                  os.chmod(address, 0o600)
              listener.listen()
  
              # all client processes own the write end of the "alive" pipe;
              # when they all terminate the read end becomes ready.
              alive_r, alive_w = os.pipe()
              try:
                  fds_to_pass = [listener.fileno(), alive_r]
                  cmd %= (
                      listener.fileno(),
                      alive_r,
                      self._preload_modules,
                      data,
                  )
                  exe = spawn.get_executable()
                  args = [exe] + util._args_from_interpreter_flags()
                  args += ["-c", cmd]
                  pid = util.spawnv_passfds(exe, args, fds_to_pass)
              except:
                  os.close(alive_w)
                  raise
              finally:
                  os.close(alive_r)
              self._forkserver_address = address
              self._forkserver_alive_fd = alive_w
              self._forkserver_pid = pid
  
imports: import errno
  import os
  import selectors
  import signal
  import socket
  import struct
  import sys
  import threading
  import warnings
  from .None import connection
  from .None import process
  from .context import reduction
  from .None import resource_tracker
  from .None import spawn
  from .None import util
label_desc: Use image node_id 7 for calling the ForkServer obj's underlying member method code with example usage: obj.ensure_running() without return types