Repository navigation
MAINT: Enable Ruff ASYNC240/ASYNC250 and move blocking path calls off the event loop - #4467
Open
MUKUNDU SAI VARUN (HARUTO-09) wants to merge 1 commit into
Open
MUKUNDU SAI VARUN (HARUTO-09) wants to merge 1 commit into
MUKUNDU SAI VARUN (HARUTO-09) wants to merge 1 commit into
Conversation
… the event loop Async functions in pyrit/ called blocking pathlib.Path methods (exists, is_file, stat, mkdir, unlink) directly on the event loop. Run them through asyncio.to_thread, matching how the rest of the codebase already does it, and fix the same pattern in the adversarial benchmark export script. Select ASYNC240 and ASYNC250 (ASYNC250 has no current hits) so new blocking calls are caught. Test code (tests/ and the frontend e2e fixture backends) and doc examples ignore ASYNC240, since blocking path calls there do not affect library users. Part of microsoft#3721.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the changes that offload blocking filesystem operations and add async lint checks.
No open issues 🎉
What changed in this PR
Completes the ASYNC stage of #3721 by moving blocking filesystem calls off the event loop and adding Ruff checks to prevent similar calls in async library code.
Changes:
- Uses
asyncio.to_threadfor path checks, directory creation, file metadata reads, and temporary-file cleanup. - Enables Ruff
ASYNC240andASYNC250to flag blocking path methods andinput()calls. - Exempts documentation, tests, and frontend end-to-end fixtures from
ASYNC240.
| File | Description |
|---|---|
pyrit/score/video_scorer.py |
Offloads video existence checks and extracted-audio cleanup. |
pyrit/score/audio_transcript_scorer.py |
Offloads audio existence checks, file metadata reads, and WAV cleanup. |
pyrit/message_normalizer/chat_message_normalizer.py |
Offloads the audio-file check before encoding. |
pyrit/memory/storage/serializers.py |
Offloads temporary audio-file cleanup. |
pyrit/common/download_hf_model.py |
Offloads model cache directory creation. |
pyproject.toml |
Enables async blocking-call checks with scoped path-call exemptions. |
build_scripts/export_adversarial_benchmark_result.py |
Offloads export directory creation. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Completes the ASYNC stage of #3721: blocking
pathlib.Pathcalls no longer run on the event loop inside async library code, and Ruff now enforces that.pyrit/(exists,is_file,stat,mkdir,unlink) onto a worker thread withasyncio.to_thread, the same pattern the codebase already uses elsewhere. Files:download_hf_model.py,serializers.py,chat_message_normalizer.py,audio_transcript_scorer.pyandvideo_scorer.py.build_scripts/export_adversarial_benchmark_result.py.ASYNC240andASYNC250inpyproject.toml.ASYNC250has no current hits and guards against blockinginput()calls.ASYNC240per-file ignores fortests/**,frontend/e2e/**(the e2e fixture backends) anddoc/**, as proposed in Enable low-noise correctness Ruff checks instead of large stylistic rule families #3721. Blocking path calls in test setup and doc examples don't affect library users, and fixing them would touch ~190 test lines.