End python code after 60 seconds

后端 未结 5 1212
甜味超标
甜味超标 2021-01-15 04:14

Below there is some fully functioning code.

I am planning to execute this code through command line, however I would like it to end after 60 seconds.

Does an

5条回答
  •  一整个雨季
    2021-01-15 04:41

    I hope this is an easy way to execute a function periodically and end after 60 seconds:

    import time
    import os
    i = 0
    def executeSomething():
     global i
     print(i)
     i += 1
     time.sleep(1)
     if i == 10:
        print('End')
        os._exit(0)
    
    
    while True:
     executeSomething()
    

提交回复
热议问题