Skip to content

Commit

Permalink
Fix Subprocess race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
meffmadd committed Feb 29, 2024
1 parent baaaca0 commit d1f73d7
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions grader_service/autograding/local_grader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
from subprocess import PIPE, CalledProcessError
from subprocess import Popen, PIPE, CalledProcessError
from typing import Optional

from traitlets.config import Config
Expand All @@ -26,7 +26,6 @@
from grader_service.orm.lecture import Lecture
from grader_service.orm.submission import Submission
from sqlalchemy.orm import Session
from tornado.process import Subprocess
from traitlets.config.configurable import LoggingConfigurable

from traitlets.traitlets import TraitError, Unicode, validate, Callable
Expand Down Expand Up @@ -426,7 +425,7 @@ def _cleanup(self):
if self.close_session:
self.session.close()

async def _run_subprocess(self, command: str, cwd: str) -> Subprocess:
async def _run_subprocess(self, command: str, cwd: str) -> Popen[bytes]:
"""
Execute the command as a subprocess.
:param command: The command to execute as a string.
Expand All @@ -435,9 +434,8 @@ async def _run_subprocess(self, command: str, cwd: str) -> Subprocess:
which resulted from the execution.
"""
try:
process = Subprocess(shlex.split(command),
stdout=PIPE, stderr=PIPE, cwd=cwd)
await process.wait_for_exit()
process = Popen(shlex.split(command), stdout=PIPE, stderr=PIPE, cwd=cwd)
process.wait()
except CalledProcessError:
self.grading_logs = process.stderr.read().decode("utf-8")
self.log.error(self.grading_logs)
Expand Down

0 comments on commit d1f73d7

Please sign in to comment.