states.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # This module must not depend on any other non-stdlib module to prevent
  2. # circular import problems.
  3. class ProcessStates:
  4. STOPPED = 0
  5. STARTING = 10
  6. RUNNING = 20
  7. BACKOFF = 30
  8. STOPPING = 40
  9. EXITED = 100
  10. FATAL = 200
  11. UNKNOWN = 1000
  12. STOPPED_STATES = (ProcessStates.STOPPED,
  13. ProcessStates.EXITED,
  14. ProcessStates.FATAL,
  15. ProcessStates.UNKNOWN)
  16. RUNNING_STATES = (ProcessStates.RUNNING,
  17. ProcessStates.BACKOFF,
  18. ProcessStates.STARTING)
  19. def getProcessStateDescription(code):
  20. return _process_states_by_code.get(code)
  21. class SupervisorStates:
  22. FATAL = 2
  23. RUNNING = 1
  24. RESTARTING = 0
  25. SHUTDOWN = -1
  26. def getSupervisorStateDescription(code):
  27. return _supervisor_states_by_code.get(code)
  28. class EventListenerStates:
  29. READY = 10 # the process ready to be sent an event from supervisor
  30. BUSY = 20 # event listener is processing an event sent to it by supervisor
  31. ACKNOWLEDGED = 30 # the event listener processed an event
  32. UNKNOWN = 40 # the event listener is in an unknown state
  33. def getEventListenerStateDescription(code):
  34. return _eventlistener_states_by_code.get(code)
  35. # below is an optimization for internal use in this module only
  36. def _names_by_code(states):
  37. d = {}
  38. for name in states.__dict__:
  39. if not name.startswith('__'):
  40. code = getattr(states, name)
  41. d[code] = name
  42. return d
  43. _process_states_by_code = _names_by_code(ProcessStates)
  44. _supervisor_states_by_code = _names_by_code(SupervisorStates)
  45. _eventlistener_states_by_code = _names_by_code(EventListenerStates)