can I run multiple def in one time

Question:

I want to run multiple def simultaneously like this

method_files.py

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?

Asked By: IFM2

||

Answers:

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()

Answered By: mehran heydarian