How do you do these two functions immediately?



  • How am I supposed to perform these two functions? In fact, in this code, to perform the function while True immediately: 300 seconds without waiting.

    time.sleep(300)
    os.system('taskkill /f /im cmd.exe')
    while True:
        print("It worked!")
    


  • If you don't use the streams, you can swam the expectation somehow.

    import time
    

    exec_time = time.perf_counter() + 5 # запуск через 5 секунд
    while True:
    print("It worked!")
    time.sleep(1)
    if exec_time and exec_time <= time.perf_counter():
    exec_time = None
    #os.system('taskkill /f /im cmd.exe')
    print('taskkill /f /im cmd.exe')

    It worked!
    It worked!
    It worked!
    It worked!
    It worked!
    taskkill /f /im cmd.exe
    It worked!
    It worked!
    It worked!


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2