Avatar ·

What does if __name__ == "__main__" do?

📁 Decorator, method, Multiprocessing, Parsing

What happens during a call  if __name__ == "__main__":?


# Threading Example
import time, thread

def MyFunction(string, sleeptime, lock, *args):
    while 1:
        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,