Launch and terminate Timeflux instances on both POSIX and Windows systems.
Sometimes, it’s okay to kill. But only if you do it gracefully, and give your victim a chance to say goodbye to his or her children and let them commit suicide (again, with grace) upon hearing such news.
On POSIX systems, it’s easy: just launch your process normally and terminate it by sending a SIGINT signal.
On Windows, well, that’s another story. SIGINT can’t be captured, and the only way is to send a CTRL+C event. Any other signal (except CTRL+BREAK) will terminate without notice. Simple enough, you might say. Not quite. It just happens that CTRL events can only be captured by processes attached to the current console. Which is pretty useless in most cases. But do not abandon all hope! Here is a (hacky) solution: have a launcher script that will start a simple TCP server and run your program. When a client connect to the server, it will send a CTRL+C event to its subprocess.
Use this helper as a script or invoke with:
python -m timeflux.helpers.handler [cmd] [args].
Launching a Timeflux instance:
python -m timeflux.helpers.handler launch timeflux -d foobar.yaml
Terminating a Timeflux instance gracefully:
python -m timeflux.helpers.handler terminate
Running Timeflux from a batch script:
@echo off set ROOT=C:\Users\%USERNAME%\Miniconda3 call %ROOT%\Scripts\activate.bat %ROOT% call conda activate timeflux start python -m timeflux.helpers.handler launch timeflux -d foobar.yaml pause call python -m timeflux.helpers.handler terminate
Launch a subprocess and exit.
- timeflux.helpers.handler.launch_windows(args, port=10000)
Launch a subprocess and await connection to a TCP server.
Find oldest Timeflux process and terminate it.
Terminate the Timeflux process by connecting to the TCP server.