Showing posts with label 【PYTHON】multiprocessing. Show all posts
Showing posts with label 【PYTHON】multiprocessing. Show all posts

Tuesday, June 1, 2021

【PYTHON】multiprocessing

 from concurrent.futures import ProcessPoolExecutor

from concurrent.futures.thread import ThreadPoolExecutor
def occupy(x):
  count = x
  for i in range(11000):
    count += i
  return count


# it will only work if run in the name == main block
if __name__ == "__main__":
  print('.submit method for multiprocessing')
  jobs = []
  with ProcessPoolExecutor() as executor:
    for i in range(4):
      job = executor.submit(occupy, i)
      jobs.append(job)

  for job in jobs:
    print(job.result())

    print('.map method for multiprocessing')        
    # or, you can do it this way
    with ProcessPoolExecutor() as executor:
      results = [r for r in executor.map(occupy, range(4))]

    print(results)


    print('threading demo')
    jobs = []
    with ThreadPoolExecutor() as executor:
      for i in range(4):
        job = executor.submit(occupy, i)
        jobs.append(job)

    for job in jobs:
      print(job.result())

Why Most Biotech GTM Strategies Fail: A Framework for 8 Biotech Business Models

TDiscover why biotech startups need different GTM strategies based on their business model. Explore 8 biotech business models and commerc...