Questions
Questions

Reputation: 185

How to invoke a external application(Windows based) independent of parent python script?

I want to invoke an external GUI application from a python script which will be triggered upon some file upload to the server.

I would like the process to be launched and kept running whereas the python script should continue and eventually finish its job and quit. I have tried different options but none proved successful.

Right now the script expects the application to be closed before script exits and sends the response.

I tried Subprocess, Popen, os.System, Spawnl, Spawnlp in the main thread as well by calling these API's in a separate thread. There are lot of questions asked in this regard in stackoverflow and other forums. But I couldn't get the exact solution for this yet.

Appreciate any help.

Upvotes: 3

Views: 274

Answers (1)

Muppet
Muppet

Reputation: 6019

had exactly the same problem and took me friggin ages to find it, but here is your answer:

import win32api
win32api.ShellExecute(0, "open", "python.exe", 'blah.py', '', 1)

This guarantees you an independent process - even after you exit the calling python program, this will continue to work.

Upvotes: 1

Related Questions