You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 line
2.0 KiB

  1. from abc import abstractmethod
  2. from signal import Signals
  3. from typing import Optional
  4. from ._resources import AsyncResource
  5. from ._streams import ByteReceiveStream, ByteSendStream
  6. class Process(AsyncResource):
  7. """An asynchronous version of :class:`subprocess.Popen`."""
  8. @abstractmethod
  9. async def wait(self) -> int:
  10. """
  11. Wait until the process exits.
  12. :return: the exit code of the process
  13. """
  14. @abstractmethod
  15. def terminate(self) -> None:
  16. """
  17. Terminates the process, gracefully if possible.
  18. On Windows, this calls ``TerminateProcess()``.
  19. On POSIX systems, this sends ``SIGTERM`` to the process.
  20. .. seealso:: :meth:`subprocess.Popen.terminate`
  21. """
  22. @abstractmethod
  23. def kill(self) -> None:
  24. """
  25. Kills the process.
  26. On Windows, this calls ``TerminateProcess()``.
  27. On POSIX systems, this sends ``SIGKILL`` to the process.
  28. .. seealso:: :meth:`subprocess.Popen.kill`
  29. """
  30. @abstractmethod
  31. def send_signal(self, signal: Signals) -> None:
  32. """
  33. Send a signal to the subprocess.
  34. .. seealso:: :meth:`subprocess.Popen.send_signal`
  35. :param signal: the signal number (e.g. :data:`signal.SIGHUP`)
  36. """
  37. @property
  38. @abstractmethod
  39. def pid(self) -> int:
  40. """The process ID of the process."""
  41. @property
  42. @abstractmethod
  43. def returncode(self) -> Optional[int]:
  44. """
  45. The return code of the process. If the process has not yet terminated, this will be
  46. ``None``.
  47. """
  48. @property
  49. @abstractmethod
  50. def stdin(self) -> Optional[ByteSendStream]:
  51. """The stream for the standard input of the process."""
  52. @property
  53. @abstractmethod
  54. def stdout(self) -> Optional[ByteReceiveStream]:
  55. """The stream for the standard output of the process."""
  56. @property
  57. @abstractmethod
  58. def stderr(self) -> Optional[ByteReceiveStream]:
  59. """The stream for the standard error output of the process."""