_convenience.py 918 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- test-case-name: twisted._threads.test.test_convenience -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Common functionality used within the implementation of various workers.
  6. """
  7. from ._ithreads import AlreadyQuit
  8. class Quit:
  9. """
  10. A flag representing whether a worker has been quit.
  11. @ivar isSet: Whether this flag is set.
  12. @type isSet: L{bool}
  13. """
  14. def __init__(self) -> None:
  15. """
  16. Create a L{Quit} un-set.
  17. """
  18. self.isSet = False
  19. def set(self) -> None:
  20. """
  21. Set the flag if it has not been set.
  22. @raise AlreadyQuit: If it has been set.
  23. """
  24. self.check()
  25. self.isSet = True
  26. def check(self) -> None:
  27. """
  28. Check if the flag has been set.
  29. @raise AlreadyQuit: If it has been set.
  30. """
  31. if self.isSet:
  32. raise AlreadyQuit()