马老师Java零基础从入门到就业
from multiprocessing import Processimport timeclass SumProcess(Process):
def __init__(self, n, e=None):
super().__init__() # 调用父类的初始化方法: 一定写,因类进程的创建由系统,初始化方法由系统调用。
self.n = n
self.e = e def run(self):
# 当前进程分配资源后,由创建的线程来执行的函数,系统调用的
s = 0
for i in range(1, self.n + 1):
if self.e and i % self.e == 0:
continue
s += i
time.sleep(0.001)
print(self.name, i)
print(self.name, self.n, '以内的所有数据和为', s)