swiftlang / swiftlang/swift-subprocess

[Feature] Add timeout parameter and TimeoutError to run API

Open
#65 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API Change enhancement
Dominant language
Swift
Stars
734
Forks
68
Avg merge
9d 2h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing run API and its subprocess execution and error-handling paths. Trace how process completion and failures are represented, then determine the API and lifecycle behavior needed for a timeout and TimeoutError. Done means the timeout is supported, the new error can be handled by callers, and coverage verifies expiration behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.