Search code examples
pythonpython-3.xmultithreadingconcurrencyparallel-processing

How to run multiple functions at the same time?


I'm trying to run 2 functions at the same time.

def func1():
    print('Working')

def func2():
    print('Working')

func1()
func2()

Does anyone know how to do this?


Solution

  • Do this:

    from threading import Thread
    
    def func1():
        print('Working')
    
    def func2():
        print("Working")
    
    if __name__ == '__main__':
        Thread(target = func1).start()
        Thread(target = func2).start()