How to set timeout [duplicate] - python

This question already has answers here:
Python Timeout script to kill thread active for more than X seconds
(2 answers)
Closed 2 years ago.
I am using a bash executable to run a python script in a loop
Sometimes the browser (run by the python script) will stop loading and stop working for hours until I manually come and close the window which will cause the executable to re-run the python script. How can I do this automatically? If no new line is shown in the terminal for 2 mins, then quit python code and run it again.
This is what I have right now:
while true ; do
python3 /Users/Name/Desktop/pythoncode.py
done
It will run the code in a loop. Now I want it to close the code and run it again if no line is outputted in the terminal for 2 mins (the python script shows its progress in the terminal)
Thanks and happy new year

I think the problem should be handled in the pythoncode.py.You can detect whether there was a change in the last 2 minutes by using a setInterval method and increase a counter for every action that is taken by the code.
If it hasn't change the last 2 minutes, you can close it. The other script will run it again.
Python Equivalent of setInterval()?
In the other python file which will run the script, you can use os.system()
Run python script only if it's not running

Related

Building a reminder [duplicate]

This question already has answers here:
How to run a python script in the background?
(6 answers)
Closed 7 years ago.
I have been trying to code a python script which reads data from a serial port. It worked well from the command line but I need it to run as a background process without any command line interface. The script has a while loop which reads the next byte of data from a serial port and simulates a key press accordingly. For the keypresses to be focused on the current window, instead of python command line, I need the script to run as a background process. I have read few answers here but nothing rang a bell for me. Please point me in the right direction.
On Windows, you can run a Python script in the background using the pythonw.exe executable, which will run your program with no visible process or way to interact with it. You also cannot terminate it without a system monitor. More information on pythonw.exe can be found in the answers to the question: pythonw.exe or python.exe?

How do I stop a Python script from running in my command line? [duplicate]

This question already has answers here:
How to stop/terminate a python script from running?
(18 answers)
Closed 2 years ago.
I recently followed a tutorial on web scraping, and as part of that tutorial, I had to execute (?) the script I had written in my command line.Now that script runs every hour and I don't know how to stop it.
I want to stop the script from running. I have tried deleting the code, but the script still runs. What should I do?
You can kill it from task manager.
I can't comment, but you must show us the script or part of the script so we can try to find out the problem or the video you were watching. Asking just a question without an example doesn't help us as much figure out the problem.
If you're using Flask, in the terminal or CMD you're running the script. Type in CTRL+C and it should stop the script. OR set the debug to false eg. app.run(debug=False) turn that to False because sometimes that can make it run in background and look for updates even though the script was stopped. In conclusion: Try to type CTRL+C or if not set debug to False

Running Python Script as a Windows background process [duplicate]

This question already has answers here:
How to run a python script in the background?
(6 answers)
Closed 7 years ago.
I have been trying to code a python script which reads data from a serial port. It worked well from the command line but I need it to run as a background process without any command line interface. The script has a while loop which reads the next byte of data from a serial port and simulates a key press accordingly. For the keypresses to be focused on the current window, instead of python command line, I need the script to run as a background process. I have read few answers here but nothing rang a bell for me. Please point me in the right direction.
On Windows, you can run a Python script in the background using the pythonw.exe executable, which will run your program with no visible process or way to interact with it. You also cannot terminate it without a system monitor. More information on pythonw.exe can be found in the answers to the question: pythonw.exe or python.exe?

why command prompt take less time to run the python program as compare to python IDLE? [duplicate]

This question already has an answer here:
Python IDLE becomes slow on very large program input
(1 answer)
Closed 8 years ago.
I want to check the running time of my program by using this.
start_time = time.time()
print(time.time() - start_time)
but the result was surprising in cmd it gives time of 1.2 sec but in python IDLE time is 5.12 sec.
why it is so?
Python IDLE is some kind of a wrapper around python environment. Let's say, it's like python.exe+wrapper. IDLE has GUI, buttons, text field,etc. So, it has to handle Python environment and the GUI at once. IDLE is a full Windows program. It's OK that it's faster to run pure python.exe than python.exe and all the stuff in IDLE.

Python script pops up console when run by scheduler [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Run python script without DOS shell appearing
I have a python script that Windows Scheduler runs every 5 minutes for me. The script works fine but every time it runs it's loading up the console really quick on my desktop before it automatically closes. Does anyone know how to remove this behavior? I'd like it to just run in the background without me knowing.
Run it through pythonw instead of python (pyw if you're using the new launcher).

Categories

Resources