Avatar ·

¿Qué hace if __name__ == "__main__"?

📁 decorador, método, multiprocesamiento, Análisis sintáctico

n

¿Qué sucede durante la llamada if __name__ == "__main__":?

n
# Threading examplenimport time, threadnndef myfunction(string, sleeptime, lock, *args):n    while 1:n        lock.acquire()n        time.sleep(sleeptime)n        lock.release()n        time.sleep(sleeptime)nif __name__ == "__main__":n    lock = thread.allocate_lock()n    thread.start_new_thread(myfunction, ("Thread #: 1", 2, lock))n    thread.start_new_thread(myfunction, ("Thread #: