怎么if __name__ == "__main__":办?
# Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while True:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock = thread.allocate_lock()
thread.start_new_thread(myfunction, ("Thread #: 1", 2, lock))
thread.start_new_thread(myfunction, ("Thread #: 2", 2, lock))
Run Code Online (Sandbox Code Playgroud) 在Windows上的python中使用多处理时,应该保护程序的入口点.文档说"确保新的Python解释器可以安全地导入主模块,而不会导致意外的副作用(例如启动新进程)".任何人都可以解释这究竟是什么意思?