from multiprocessing import Process defworker_function(name):print(f"Worker {name} is working")if __name__ =="__main__":# 创建进程实例 p1 = Process(target=worker_function, args=("Process 1",)) p2 = Process(target=worker_function, args=("Process 2",))# 启动进程 p1.start() p2.start()# 等待进程结束 p1.join() p2.join()print("All processes done.")
方法二 继承
from multiprocessing import Process
import timeclassMyProcess(Process):defrun(self):print('into process ……')time.sleep(1)p = MyProcess()
p.start()print("---主---")
三、使用Pool创建进程池
from multiprocessing import Pool defworker_function(num):return num * num if __name__ =="__main__":# 创建一个进程池,包含4个进程 with Pool(processes=4)as pool:# 使用map方法分发任务到进程池 results = pool.map(worker_function,[1,2,3,4,5])print(results)# 输出: [1, 4, 9, 16, 25]
四、使用Process和管道进行进程间通信
from multiprocessing import Process, Pipe defworker(conn):print("Worker process started") conn.send("Hello from worker!") conn.close()if __name__ =="__main__": parent_conn, child_conn = Pipe() p = Process(target=worker, args=(child_conn,)) p.start()print("Parent process received:", parent_conn.recv()) p.join()
针对图计算的近数据计算架构的代表性工作有: Seoul National University的 Tesseract和 Georgia Institute of Technology 的 GraphPIM,具体如下。
1 Tesseract Tesseract是一个针对图计算的可编程的内存计算系统架构,它综合了图计算的特点&…