module documentation

This script provides a consistent environment for services to run in. The basic architecture is:

  • parent process (python, ipython, etc.)
    • this process, referred to as the "current" process (service/main.py)
      • child process (the service)
        • (optional): any child processes that the service creates
  • clients (any other Python processes that are using this service) - see below

Some services that we spin up do not terminate on their own when their parent process terminates, so they need to be killed explicitly. However, if the parent process is a Python interpreter that is in the process of shutting down, it cannot reliably kill its children. This script works around these issues by detecting when the parent process exits, terminating its children, and only then exiting itself.

Some services can also only have a single running instance per user. Notably, only one instance of MongoDB can use a given data folder. To support this, when invoked with the "--multi" option, this script allows additional "clients", i.e. other Python processes using FiftyOne, to register themselves at any time. This script will continue running in the background and keep the child process alive until all registered clients, including the original parent process, have exited.

Copyright 2017-2025, Voxel51, Inc.

Class ChildStreamMonitor Monitor for an output stream (stdout or stderr) of a child process.
Class ClientMonitor Monitor to keep track of all clients using this service.
Class ExitMode Undocumented
Function monitor_stdin Trigger shutdown when the parent process closes this process's stdin. This will occur if the fiftyone.core.service.DatabaseService singleton destroyed.
Function shutdown Kill subprocesses and wait for them to finish.
Function start_daemon_thread Undocumented
Function trigger_exit Start the shutdown process.
Variable args Undocumented
Variable child Undocumented
Variable child_stderr Undocumented
Variable child_stdout Undocumented
Variable client_monitor Undocumented
Variable command Undocumented
Variable exit_mode Undocumented
Variable exiting Undocumented
Variable lock Undocumented
Variable parser Undocumented
Variable popen_kwargs Undocumented
Variable stdin_thread Undocumented
def monitor_stdin(): (source)

Trigger shutdown when the parent process closes this process's stdin. This will occur if the fiftyone.core.service.DatabaseService singleton destroyed.

This should only occur when the parent process has exited.

def shutdown(): (source)

Kill subprocesses and wait for them to finish.

Also dumps output if the main child process fails to exit cleanly.

def start_daemon_thread(target): (source)

Undocumented

def trigger_exit(mode): (source)

Start the shutdown process.

Undocumented

Undocumented

child_stderr = (source)

Undocumented

child_stdout = (source)

Undocumented

client_monitor = (source)

Undocumented

Undocumented

exit_mode = (source)

Undocumented

Undocumented

Undocumented

Undocumented

popen_kwargs: dict = (source)

Undocumented

stdin_thread = (source)

Undocumented