-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write submission script to temp #501
Conversation
WalkthroughThe changes in this pull request involve the modification of the Changes
Possibly related PRs
Poem
Warning Rate limit exceeded@jan-janssen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 59 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
executorlib/cache/queue_spawner.py (1)
57-57
: Consider queue system requirements for submission scriptsThe temporary file handling should align with the queue system's requirements:
- Some queue systems might need to access the submission script during job execution
- The script location might need specific permissions or path requirements
- Cleanup timing should consider the job's lifecycle
Consider:
- Documenting the queue system's requirements for submission scripts
- Moving temporary files to a designated directory with appropriate permissions
- Implementing a cleanup strategy based on job status (e.g., after job completion)
- Adding configuration options for submission script handling
Would you like me to help create a more comprehensive solution that addresses these architectural concerns?
🧰 Tools
🪛 Ruff
57-57: Use a context manager for opening files
(SIM115)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
executorlib/cache/queue_spawner.py
(2 hunks)
🧰 Additional context used
🪛 Ruff
executorlib/cache/queue_spawner.py
57-57: Use a context manager for opening files
(SIM115)
🔇 Additional comments (2)
executorlib/cache/queue_spawner.py (2)
3-3
: LGTM!
The tempfile import is appropriately placed with other standard library imports.
57-57
: Verify queue system compatibility
Let's verify how the submission script path is used across different queue systems.
✅ Verification successful
Let me gather more context about how the submission script path is used within the queue spawner implementation.
Using NamedTemporaryFile().name
is safe in this context
The verification shows that the temporary file path is used correctly within the queue submission context:
- The
submission_script_path
is only used as a parameter insubmit_kwargs
for theQueueAdapter.submit_job()
method - The implementation is self-contained within the
queue_spawner.py
file - The temporary file handling follows Python's standard practice using the
tempfile
module - The path is used as a parameter value and not directly manipulated or accessed elsewhere in the codebase
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for queue system specific implementations and usage of submission scripts
echo "Searching for queue system implementations..."
rg -l "QueueAdapter|submit_job"
echo "Checking submission script usage..."
rg "submission_script"
echo "Looking for existing temporary file handling..."
rg "tempfile|mkstemp"
Length of output: 671
Script:
#!/bin/bash
# Get the implementation details of queue_spawner.py
echo "Content of queue_spawner.py:"
cat executorlib/cache/queue_spawner.py
# Search for any test files related to queue spawner
echo -e "\nSearching for related test files:"
fd "test.*queue.*" --type f
Length of output: 4494
🧰 Tools
🪛 Ruff
57-57: Use a context manager for opening files
(SIM115)
@@ -53,6 +54,7 @@ def execute_with_pysqa( | |||
"command": " ".join(command), | |||
"dependency_list": [str(qid) for qid in task_dependent_lst], | |||
"working_directory": os.path.abspath(cwd), | |||
"submission_script_path": tempfile.NamedTemporaryFile().name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Improve temporary file handling
The current implementation has several issues:
- The temporary file might be deleted before the queue system can access it
- No proper resource cleanup
- Missing error handling
- File permissions aren't explicitly set
Here's a safer implementation:
- "submission_script_path": tempfile.NamedTemporaryFile().name,
+ "submission_script_path": tempfile.mkstemp(prefix="job_", suffix=".sh", text=True)[1],
Additionally, consider implementing proper cleanup:
def execute_with_pysqa(...):
temp_files = []
try:
# Create temp file with mkstemp
fd, temp_path = tempfile.mkstemp(prefix="job_", suffix=".sh", text=True)
os.close(fd) # Close the file descriptor
temp_files.append(temp_path)
submit_kwargs = {
# ... other kwargs ...
"submission_script_path": temp_path,
}
# ... rest of the function ...
finally:
# Cleanup temp files after job submission
for temp_file in temp_files:
try:
if os.path.exists(temp_file):
os.remove(temp_file)
except OSError:
pass # Best effort cleanup
This solution:
- Uses
mkstemp
to create a persistent temporary file - Implements proper cleanup after job submission
- Uses appropriate file permissions
- Includes error handling
🧰 Tools
🪛 Ruff
57-57: Use a context manager for opening files
(SIM115)
Summary by CodeRabbit
New Features
Bug Fixes
Documentation