I have a python script and I imported another script (a simple GUI window) using:
import gui
So when I run the code, the GUI pops up and I need to close the GUI in order for the script to continue executing.
Is there any way to run the entire script while keeping the GUI window open the whole time?
You might be able to do this with threading in which the GUI is running off a child thread while the rest of the script runs on the main thread.
I am writing a python program (3.8) which is automatically filling in certain options in a command window using a menu format. For example, when prompted with
It would fill the correct option (either 1 or 2).
Currently, the .exe file must be opened separately from the python file which is a hassle. To remove this I tried using subprocess like this.
import subprocess
subprocess.call([r'C:\Users\file\location\that\ends\right\here\VSCaptureMP.exe'])
but it pauses the entire program until the .exe window is closed. The rest of the program (the automatic writing part) never gets to run when using this format.
I know there is an after module when using tkinter. Is there a similar option for this scenario?
Use subprocess.Popen
import subprocess
print("Hello")
subprocess.Popen([r"C:\Windows\system32\mspaint.exe"])
print("This is non-blocking!")
I'm on Windows 7. I have a program that launches a Python script using the system Python interpreter. The process quickly finishes. I want a way to see the process, its command line arguments, and any other information about it. (PID?)
How can I do this? The process is killed before I could open Process Explorer. I can cause the program to launch the Python script whenever I want.
I would like to create a simple Python program that will concurrently execute 2 independent scripts. For now, the two scripts just print a sequence of numbers but my intention is to use this program to concurrently run a few Twitter streaming programs in the future.
I suspect I need to use subprocess.Popen but I cannot quite get my head around what arguments I should put in there. There was a similar question on StackOverflow but the code provided there (pasted below) doesn't print anything. I will appreciate your help.
My files are:
thread1.py
thread2.py
import subprocess
subprocess.Popen(['screen', './thread1.py']))
subprocess.Popen(['screen', './thread2.py'])
Use supervisord
supervisord is process control system just for the purpose of running multiple command line scripts.
It features:
multiple controlled processes
autorestarting failed runs
log stdout and stderr output
starting scripts in order (using priority)
command line utility to view latest log output, stop, start, restart the processes
This solution works only on *nix based systems, it is not available on Windows.
As wanderlust mentioned, why do you want to do it this way and not via linux command line?
Otherwise, the solution you post is doing what it is meant to, i.e, you are doing this at the command line:
screen ./thread1.py
screen ./thread2.py
This will open a screen session and run the program and output within this screen session, such that you will not see the output on your terminal directly. To trouble shoot your output, just execute the scripts without the screen call:
import subprocess
subprocess.Popen(['./thread1.py'])
subprocess.Popen(['./thread2.py'])
Content of thread1.py:
#!/usr/bin/env python
def countToTen():
for i in range(10):
print i
countToTen()
Content of thread2.py:
#!/usr/bin/env python
def countToHundreds():
for i in range(10):
print i*100
countToHundreds()
Then don't forget to do this on the command line:
chmod u+x thread*.py
You can also just open several Command Prompt windows to run several Python programs at once - just run one in each of them:
In each Command Prompt window, go to the correct directory (such as C:/Python27) and then type 'python YourCodeNo1.py' in one Command Prompt window, 'python YourCodeNo2.py' in the next one ect. .
I'm currently running 3 codes at one time in this way, without slowing any of them down.
I need to create a python script that monitors another python script, specifically, some variables from it. I was thinking of creating an independent thread in the "observer script" that does this. This thread must run until the "executer script" finishes. Maybe all of this can be done inside one big script (observer+executer), I really do not know at the moment.
Is it possible at all to do this with python in windows?