Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

windows

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.

like image 800
Questions Avatar asked Mar 13 '26 13:03

Questions


1 Answers

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.

like image 71
Muppet Avatar answered Mar 15 '26 02:03

Muppet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!