mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-11 04:19:25 +00:00
Apply review comments
This commit is contained in:
26
sith/composer.py
Normal file
26
sith/composer.py
Normal file
@ -0,0 +1,26 @@
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import psutil
|
||||
|
||||
COMPOSER_PID = "COMPOSER_PID"
|
||||
|
||||
|
||||
def start_composer(procfile: str):
|
||||
"""Starts the composer and stores the PID as an environment variable
|
||||
This allows for running smoothly with the django reloader
|
||||
"""
|
||||
process = subprocess.Popen(
|
||||
[sys.executable, "-m", "honcho", "-f", procfile, "start"],
|
||||
)
|
||||
os.environ[COMPOSER_PID] = str(process.pid)
|
||||
|
||||
|
||||
def stop_composer():
|
||||
"""Stops the composer if it was started before"""
|
||||
if (pid := os.environ.get(COMPOSER_PID, None)) is not None:
|
||||
process = psutil.Process(int(pid))
|
||||
process.send_signal(signal.SIGTERM)
|
||||
process.wait()
|
Reference in New Issue
Block a user