Home > other >  can I run multiple def in one time
can I run multiple def in one time

Time:07-27

I want to run multiple def in one time like this

def one() :
    print("hi")

def two() :
    print("hi2")

def three() :
    print("hi3")

main.py:

from one import one

from two import two

from three import three

one()
two()
three()

I want to run these commands once:

one()
two()
three()

can I do this?

CodePudding user response:

use threading

import threading

def function_1():
   print("1")

def function_2():
   print("2")

Thread1 = threading.Thread(target=function_1)
Thread2 = threading.Thread(target=function_2)

Thread1.start()
Thread1.start()
Thread1.join()
Thread2.join()

or you can use multiprocessing

from multiprocessing import Process

proccess1 = Process(target=function_1)
proccess2 = Process(target=function_2)

proccess1.start()
proccess2.start()

proccess1.join()
proccess2.join()

  • Related