Home:ALL Converter>Python: GUI for continuously running script

Python: GUI for continuously running script

Ask Time:2015-04-23T05:32:53         Author:rahulchem

Json Formatter

I am writing a script which will run continuously on a computer. As it has to run on a computer without python installation, I am planning to convert it to executable. I also want to have a GUI to start and stop this application but I don't want this GUI to be opened all the time. I mean if the GUI is closed, I don't want the executable to stop running. It should stop only if user presses stop button on GUI. This GUI is just a interface for users to start and stop the executable.

How can I achieve this behavior?

Author:rahulchem,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29809269/python-gui-for-continuously-running-script
abarnert :

The obvious solution is to have two separate programs: a backgrounder/daemon/agent/service that just chugs along in the background detached from user input and output, and a GUI program to control it. A nice advantage of this design is that you can also have a command-line program to control it, if you ever want to ssh in remotely, or control it from a script.\n\n\n\nThe traditional Unix way of handling this is to use a daemon designed like a system service (even if it's run like a normal user): it writes its pid to a file when it starts up, and the control program reads that file and sends a signal to the pid that it finds to kill it.\n\nSo, the control program has functions something like this:\n\ndef is_running():\n try:\n with open(PID_PATH) as f:\n pid = int(f.read())\n os.kill(pid, 0)\n except Exception:\n return False\n else:\n return True\n\ndef stop():\n with open(PID_PATH) as f:\n pid = int(f.read())\n os.kill(pid, signal.SIGUSR1)\n\ndef start():\n subprocess.check_call(DAEMON_PATH)\n\n\nOf course in real life, you'll want some better error handling. Also, which signal you use depends on whether you want the daemon to die hard and instantly, or to gracefully shut down. And so on.\n\n\n\nAn alternative is to have the background process listen on a socket—whether TCP with a known port, or a Unix socket with a known filename—and communicate with it that way. This allows you to do fancier things that just start and stop.\n\n\n\nOn Windows, the details aren't quite the same, but you can do something similar.\n\n\n\nFinally, Windows, OS X, and various linux distros also all have platform-specific ways of wrapping this kind of thing up at a higher level, so you might want to build a Windows Service, LaunchAgent, etc.",
2015-04-22T21:43:48
yy