Is your feature request related to a problem? Please describe.
When executing external processes using the run API, there's currently no way to set a time limit for their execution. This can be problematic if a subprocess becomes unresponsive or takes an excessively long time to complete, potentially leading to the calling application hanging indefinitely or consuming excessive resources.
Describe the solution you'd like
I'd like to propose adding a timeout parameter to the run API. If the subprocess execution time exceeds this specified timeout value, the run function should throw a new error type, perhaps named TimeoutError. This would allow users to gracefully handle scenarios where a subprocess exceeds its expected execution time. Upon catching a TimeoutError, users could then choose to inspect the process's PID (if available) and programmatically terminate the hanging process if necessary.
Describe alternatives you've considered
Currently, managing timeouts would require implementing custom timer mechanisms and process monitoring outside of swift-subprocess, which adds complexity and boilerplate code for a common use case.
Additional context
This feature is inspired by similar functionality found in other languages' subprocess libraries. For example, Python's subprocess.run function offers a timeout parameter and raises a TimeoutExpired exception, providing a robust way to manage long-running processes. You can refer to the Python documentation here: https://docs.python.org/3.13/library/subprocess.html#using-the-subprocess-module
Is your feature request related to a problem? Please describe.
When executing external processes using the
runAPI, there's currently no way to set a time limit for their execution. This can be problematic if a subprocess becomes unresponsive or takes an excessively long time to complete, potentially leading to the calling application hanging indefinitely or consuming excessive resources.Describe the solution you'd like
I'd like to propose adding a timeout parameter to the
runAPI. If the subprocess execution time exceeds this specifiedtimeoutvalue, the run function should throw a new error type, perhaps namedTimeoutError. This would allow users to gracefully handle scenarios where a subprocess exceeds its expected execution time. Upon catching aTimeoutError, users could then choose to inspect the process's PID (if available) and programmatically terminate the hanging process if necessary.Describe alternatives you've considered
Currently, managing timeouts would require implementing custom timer mechanisms and process monitoring outside of swift-subprocess, which adds complexity and boilerplate code for a common use case.
Additional context
This feature is inspired by similar functionality found in other languages' subprocess libraries. For example, Python's subprocess.run function offers a timeout parameter and raises a TimeoutExpired exception, providing a robust way to manage long-running processes. You can refer to the Python documentation here: https://docs.python.org/3.13/library/subprocess.html#using-the-subprocess-module