Last active
January 30, 2017 15:25
-
-
Save tbnorth/3cdf7792f80d08abfa96118db5a47c94 to your computer and use it in GitHub Desktop.
Python script to scan task list and launch missing background tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| launcher.py - scan running tasks and launch as needed. Useful on Windows where | |
| cygwin's ps isn't informative and procps may be unavailable. | |
| Terry N. Brown, [email protected], Mon Jan 30 09:20:30 2017 | |
| """ | |
| import sys | |
| from subprocess import Popen, PIPE | |
| import psutil | |
| targets = { | |
| 'winbut': "python d:/local/winbut.py", | |
| 'report_reminder': "python d:/local/report_reminder.py", | |
| } | |
| for pid in psutil.pids(): | |
| try: | |
| proc = psutil.Process(pid) | |
| except psutil.NoSuchProcess: | |
| continue | |
| if 'python' not in proc.name(): | |
| continue | |
| targets = { | |
| k:v for k,v in targets.items() | |
| if k not in ' '.join(proc.cmdline()) | |
| } | |
| if not targets: | |
| break | |
| for target, prog in targets.items(): | |
| print(prog) | |
| cmd = prog.split() | |
| CREATE_NEW_PROCESS_GROUP = 0x00000200 | |
| DETACHED_PROCESS = 0x00000008 | |
| Popen( | |
| cmd, # stdin=PIPE, stdout=PIPE, stderr=PIPE, | |
| stdout=sys.stdout, stderr=sys.stderr, | |
| creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment