daemon

Share RLock between multiple instances of Python

Share RLock between multiple instances of Python with multiprocessing Question: Consider this MWE: from multiprocessing import RLock class TheSetup: def __init__(self): self._hardware_lock = RLock() def hold_hardware(self): return self._hardware_lock def do_thing_with_hardware(self): with self._hardware_lock: print(‘Doing thing…’) def do_other_thing_with_hardware(self): with self._hardware_lock: print(‘Doing other thing…’) if __name__==’__main__’: from multiprocessing.managers import BaseManager class TheSetupManager(BaseManager): pass the_setup = TheSetup() TheSetupManager.register(‘get_the_setup’, callable=lambda:the_setup) …

Total answers: 2

The workers in ThreadPoolExecutor is not really daemon

The workers in ThreadPoolExecutor is not really daemon Question: The thing I cannot figure out is that although ThreadPoolExecutor uses daemon workers, they will still run even if main thread exit. I can provide a minimal example in python3.6.4: import concurrent.futures import time def fn(): while True: time.sleep(5) print(“Hello”) thread_pool = concurrent.futures.ThreadPoolExecutor() thread_pool.submit(fn) while True: …

Total answers: 2

Run a python script with supervisor

Run a python script with supervisor Question: I copied from here to run my Python code as a daemon. For extra uptime. I thought it would be a better Idea to use supervisor to keep this daemon running. I did this. python_deamon.conf [program:python_deamon] directory=/usr/local/python_deamon/ command=/usr/local/python_venv/bin/python daemon_runnner.py start stderr_logfile=/var/log/gunicorn.log stdout_logfile=/var/log/gunicorn.log autostart=true autorestart=true The problem is that …

Total answers: 5

celery daemon – permission denied on log file

celery daemon – permission denied on log file Question: I have been working on setting up my celery task as a daemon in order to process data on a schedule. I have been following the docs in order to set up my daemon, but have been running into a log file permission error that has …

Total answers: 3

How to spawn a new independent process in Python

How to spawn a new independent process in Python Question: I have a some Python code that occasionally needs to span a new process to run a shell script in a “fire and forget” manner, i.e. without blocking. The shell script will not communicate with the original Python code and will in fact probably terminate …

Total answers: 2

How to process SIGTERM signal gracefully?

How to process SIGTERM signal gracefully? Question: Let’s assume we have such a trivial daemon written in python: def mainloop(): while True: # 1. do # 2. some # 3. important # 4. job # 5. sleep mainloop() and we daemonize it using start-stop-daemon which by default sends SIGTERM (TERM) signal on –stop. Let’s suppose …

Total answers: 9

Daemon vs Upstart for python script

Daemon vs Upstart for python script Question: I have written a module in Python and want it to run continuously once started and need to stop it when I need to update other modules. I will likely be using monit to restart it, if module has crashed or is otherwise not running. I was going …

Total answers: 3

Launch an independent process with python

Launch an independent process with python Question: I have a python script and I want to launch an independent daemon process. I want to call ym python script, launch this system tray dameon, do some python magic on a database file and quit, leaving the system tray daemon running. I have tried os.system, subprocess.call, subprocess.Popen, …

Total answers: 3

How do I run long term (infinite) Python processes?

How do I run long term (infinite) Python processes? Question: I’ve recently started experimenting with using Python for web development. So far I’ve had some success using Apache with mod_wsgi and the Django web framework for Python 2.7. However I have run into some issues with having processes constantly running, updating information and such. I …

Total answers: 3