Avatar ·

¿Qué hace if __name__ == “__main__”?

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

n

¿Qué sucede durante una llamada & nbsp; if __name__ == "__main__": ?

n
 Class = "Hljs Language-Python" Data-Highlighted = "Yes"> # Ejemplo de Threading  n  Import  Time, Threadnn  Def   MyFunction  ( string, Sleeptime, Lock, *Args ): N  While   1 : n lock.acquire () n time.sleep (Sleeptime) n lock.release () n time.sleep (Sleeptime) n  if  __name__ ==  "__ main__" : n lock = thread.allocate_lock () n Thread.start_new_thread (MyFunction, ( "Thread #: 1" ,  2 , Lock)) Thread.start_new_thread (MyFunction,