import time import os from multiprocessing import Process
defgreet(): print(f"{time.time()}:hello from {os.getpid()}(parent: {os.getppid()})") time.sleep(2) print(f"{time.time()}:bye from {os.getpid()}(parent: {os.getppid()})")
if __name__ == "__main__": proc_list = [ Process(target=greet, args=(f"Process-{index}",)) for index in range(1, 5) ] for proc in proc_list: proc.start()
import os import time from threading import Thread
defgreet(): print(f"{time.time()}:hello from {os.getpid()}(parent: {os.getppid()})") time.sleep(2) print(f"{time.time()}:bye from {os.getpid()}(parent: {os.getppid()})")
if __name__ == "__main__": thread_list = [ Thread(target=greet, args=(f"Thread-{index}",)) for index in range(1, 5) ] for thread in thread_list: thread.start()