python类内部实现多进程
工作中写一个自动化脚本, 为了提高效率, 需要在类的内部启多进程, 代码逻辑如下:
# –*– coding: utf-8 –*–
# @Time : 2019/3/19 21:11
# @Author : Damon_duanlei
# @FileName : process.py
# @BlogsAddr : https://blog.youkuaiyun.com/Damon_duanlei
import time
class A(object):
def __init__(self):
self.a = None
self.b = None
def get_num_a(self):
print("计算逻辑A")
time.sleep(3)
self.a = 10
def get_num_b(self):
print("计算逻辑B")
time.sleep(5)
self.b = 6
def sum(self):
print("a的值为:{}".format(self.a))
print("b的值为:{}".format(self.b))
ret = self.a + self.b
return ret
def run(self):
self.get_num_a()
self.get_num_b(</