我有一个脚本,其中包含这样的代码
import time
def myFunction():
// Do something in background by using Process()
print("Running the first time")
myFunction()
print("Running the second time (and wait 3 seconds)")
myFunction()
time.sleep(3)
print("Running the last time")
myFunction()
time.sleep(3)
我想防止重复处理。所以输出应该是这样的
Running the first time
[myFunction] Working on something! This will take about 2 seconds to finish the process
Running the second time (and wait 3 seconds)
[myFunction] Sorry! the latest process is still working
[myFunction] Process done!
Running the last time
[myFunction] Working on something! This will take about 2 seconds to finish the process
[myFunction] Process done!
有没有办法在Python中创建这样的函数?