How to Stop a Python Script (Keyboard and Programmatically)

preview_player
Показать описание

►► Do you want to thrive as a self-employed Python freelancer controlling your own time, income, and work schedule?

⁉️ Do you have a question? Leave a comment and we will answer as soon as possible!

⏰ Subscribe to the channel, never miss a new video!

🐍 Did you know? Finxter is one of the top 10 Python Blogs on the internet!

🚀 More about Python & Freelancing:

#finxter #python

Do you want to thrive as a self-employed Python freelancer controlling your own time, income, and work schedule? Check out our Python freelancer resources:

Finxter Python Freelancer Course:

Finxter Python Freelancer Webinar:

Leaving the Rat Race with Python (Book):
Рекомендации по теме
Комментарии
Автор

Hey, I have a long Programm with a lot of pyautogui clicks. If one thing goes wrong it becames a disaster.
Is it possible to make a hotkey for Quiting?
Like: if keyboard.is_pressed('q'):
exit()
If this is possible, where have I to place this command?
At the Top (Beginning) or as the last Line?

dragondeport
Автор

This was very helpful. I'm looking for a way to stop my script programmatically but by using the time function. So exit stop after 60 minutes of running. I'm just not finding any answers. I just stumbled on this while looking.

manairband
Автор

I found a solution to my below question.
import os
import threading
import datetime
from threading import Timer
from datetime import datetime
def exitfunc():
print("Exit Time", datetime.now())
os._exit(0)
Timer(60, exitfunc).start() #exit in 60 seconds
while True: #my code

manairband