# 多进程
class MyProcess(multiprocessing.Process):
def __init__(self, name, year, startln, len):
multiprocessing.Process.__init__(self)
self.name = name
self.year = year
self.startln = startln
self.len = len
def run(self):
logger.debug("Starting " + self.name)
db_execute(self.year, self.startln, self.len)
logger.debug("Exiting " + self.name)
def db_execute(year, startln, len):
print('测试函数')
if __name__ == '__main__': # 多进程必需写在main里,否则会报错!
for i in [1990, 1991, 1992, 1993, 1995]:
process = MyProcess('process' + str(i), i, 250000, 30000) # 第一个进程起点+进程间间隔*(进程编号-1), 单个进程数据量
process.start()
process4 = MyProcess('process1994', 1994, 900000, 30000) # 第一个进程起点+进程间间隔*(进程编号-1), 单个进程数据量
process4.start()
python多进程
最新推荐文章于 2024-03-27 09:33:30 发布