Answer the question
In order to leave comments, you need to log in
Why can't I run a file delete daemon (doesn't delete anything) in a docker container (from python:3.7-slim image)?
Tried like this:
Dockerfile
FROM python:3.7-slim
COPY . .
RUN python -m pip install -r requirements.txt
CMD python daemin.py start && python main.py
import os
import time
import sys
import atexit
import signal
from pathlib import Path
class Daemon:
"""A generic daemon class.
Usage: subclass the daemon class and override the run() method.
"""
....
class MyDaemon(Daemon):
def __init__(self, audio_directory, pidfile, every_n_minutes: int = 8):
super().__init__(pidfile)
self.audio_directory = audio_directory
self.secs = every_n_minutes * 60
def run(self):
while True:
wav_clean_deamon(self.audio_directory)
time.sleep(self.secs)
if __name__ == "__main__":
daemon = MyDaemon(
audio_directory=str(Path(".").resolve() / "temp"),
pidfile="/tmp/mydaemon.pid",
every_n_minutes=1)
if len(sys.argv) == 2:
if "start" == sys.argv[1]:
daemon.start()
elif "stop" == sys.argv[1]:
daemon.stop()
elif "restart" == sys.argv[1]:
daemon.restart()
else:
print("Unknown command")
sys.exit(2)
sys.exit(0)
else:
print("usage: %s start|stop|restart" % sys.argv[0])
sys.exit(2)
if __name__ == "__main__":
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
address = f"localhost:8181"
server.add_insecure_port(address)
server.start()
server.wait_for_termination()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question