0

This is my code when I run this I want to exit the indicated time but I exit only EndScript I want a full script exit how I get an exit. please suggest to me thank you.

import threading
import datetime
import sys
from time import sleep


def EndScript():
    while True:
        print("============== EndScript Calling ==================", datetime.datetime.now().hour, datetime.datetime.now().minute)
        if datetime.datetime.now().hour >= 12 and datetime.datetime.now().minute >= 6:
            sys.exit()
        sleep(5)

def StartScript():
    thread1 = threading.Thread(target=EndScript)
    thread1.start()
    while True:
        print("===================== StartScript Calling ====================")
        sleep(2)
    

if(__name__ == '__main__'):
    StartScript()

1 Answers1

0

sys.exit() raises the SystemExit exception, as does thread.exit(). So, when sys.exit() raises that exception inside that thread, it has the same effect as calling thread.exit(), which is why only the thread exits. more

In your use case, you can call os._exit(0) to exit the program on os level

Suryaveer Singh
  • 577
  • 2
  • 13