Skip to content

Terminate ruff when it times out - #77

Open
Danipulok wants to merge 1 commit into
pydantic:mainfrom
Danipulok:fix/ruff-timeout
Open

Terminate ruff when it times out#77
Danipulok wants to merge 1 commit into
pydantic:mainfrom
Danipulok:fix/ruff-timeout

Conversation

@Danipulok

@Danipulok Danipulok commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #72.

What

ruff_check calls Popen.communicate(..., timeout=10) with no try around it.
The stdlib does not kill the child when that timeout fires, so a ruff process
that hangs is left running and its stdout and stderr pipes are never closed.
The call now kills the process and waits for it before letting the
TimeoutExpired propagate, so the error a caller sees is unchanged.

Measured on a child that sleeps for 30 seconds against a 0.5 second timeout:

after poll() stdin stdout stderr
TimeoutExpired None closed open open
kill() and a second communicate() -9 closed closed closed

That second row is why there is no with Popen(...) block: the second
communicate() already closes every pipe, so wrapping the call would reindent
the whole function and change nothing else.

How to test

make test.

test_ruff_timeout_kills_the_process replaces Popen in pytest_examples.lint
with a subclass whose first communicate raises TimeoutExpired and whose
second delegates to the parent, so the child is a real ruff process and the
kill is real. Without the fix it fails on assert ruff_process.poll() is not None.

@Danipulok

Copy link
Copy Markdown
Contributor Author

Hey @samuelcolvin!

I'm really sorry for pinging you if it's inappropriate
I've create some simple PRs and have plans for more (including reading config parts from pyproject.toml)

Would you or someone else be able to check them?
I've tried to make them as simple as possible for the beginning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up Needed

1 participant