0
def growl_request(application, hosts, password, message, title):
    for host in hosts:
        request = f"/usr/local/bin/growlnotify --sticky --title '{title}' --application 
        '{application}      ' --host '{host}' --password '{password}' '{message}'"
        proc = subprocess.Popen([request], shell=True)
        time.sleep(10)
        # proc.terminate()
        proc.kill()

I am using python to call an application that sends growl notifications. It works. However, the application growlnotify never dies. So eventually, the server crashes as it runs out of memory and processor as every run of growlnotify continues showing up in HTOP. I am experimenting with different attempts to terminate or kill the process after it runs but nothing seems to work. How do I get the subprocess to terminate once it has run? I would preferably like to eliminate the sleep and just get the process to run, complete, and then close. What am I doing wrong here?

ILikeTurtles
  • 1,012
  • 4
  • 16
  • 47
  • Did you explore any of the answer for [How to terminate a python subprocess launched with shell=True](https://stackoverflow.com/questions/4789837/how-to-terminate-a-python-subprocess-launched-with-shell-true)? Or answers to similar questions when searching with your questions title? – wwii Jun 07 '22 at 18:52
  • In this case, you have no good _reason_ to use `shell=True`, and if you didn't use it this problem wouldn't happen, because your `proc` would refer direct to `growlnotify` instead of referring to a shell responsible for starting `growlnotify`; once you solve that, your `TERM` or `KILL` will be delivered to the right place. – Charles Duffy Jun 07 '22 at 19:08

0 Answers0