Skip to content

Instantly share code, notes, and snippets.

@ghosx
Created November 8, 2019 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghosx/70a8c8bc37d2fbdda2075a44fc37f947 to your computer and use it in GitHub Desktop.
Save ghosx/70a8c8bc37d2fbdda2075a44fc37f947 to your computer and use it in GitHub Desktop.
import time
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
class A(object):
def __init__(self, name, b_list):
self.name = name
self.bs = b_list
def sign(self):
p = ProcessPoolExecutor(4)
for i in self.bs:
p.submit(i.sign_one)
p.shutdown()
print("ok")
class B(object):
def __init__(self, name, ):
self.name = name
def print(self):
print(self.name)
time.sleep(3)
def sign_one(self):
t = ThreadPoolExecutor(5)
t.submit(self.print)
t.shutdown()
if __name__ == '__main__':
bb = [B("b1"), B("b2")]
aa = A("a1", bb)
aa.sign()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment