lia1000
lia1000

Reputation: 169

Python built exe process to kill itself after a period of time

How is it possible to get a compiled .exe program written in Python to kill itself after a period of time after it is launched?

If I have some code and I compile it into an .exe, then launch it and it stays in a 'running' or 'waiting' state, how can I get it to terminate after a few mins regardless of what the program is doing?

The reason why is that the exe that is launched envokes a URL using PAMIE and automates some clicks. What I have noticed is that if the browser is closed the process remains in memory and does not clean itself up. I wanted to find a way to auto-clean up the process after say 5 mins which is more then enough time. I've tried using psutils to detect the process but that does not work in my case. Any suggestions is greatly appreciated.

Upvotes: 0

Views: 1732

Answers (2)

Morten Larsen
Morten Larsen

Reputation: 503

def one(Time):
    time.sleep(Time)
    sys.exit(0)

def two():
    thread.start_new_thread(one, (600,)) #10min countdown..
    #Your running function here....Will run sim. with function one. when time ends,
    #sys.exit exits program..(Not tested:) )

two()

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 613362

  1. Create a thread when your process starts.
  2. Make that thread sleep for the required duration.
  3. When that sleep is over, kill the process.

Upvotes: 0

Related Questions