F
F
FewSeconds2021-07-27 12:42:25
Python
FewSeconds, 2021-07-27 12:42:25

How to solve the problem/feature/limitation of multiprocessing?

Hello, I ran into the following problem:

I have a certain function that is running multi-threaded, but I would like one more function to be called multi-threaded inside this function. Unfortunately, no matter how hard I try, a lot of errors pop up in the terminal all the time. I tried googling, but didn't really understand anything. Calling a function multithreaded is possible only in the if __name__ == "main" construct.

The code
from multiprocessing import Pool

def some_func2(num):
  
  print(num)
  return

def some_func(num):

  some_list = [1,2,3,4]
  some_list.append(num)

  p2 = Pool(processes=2)
  p2.map(some_func2, some_list)

  return

if __name__ == '__main__':

  some_list = [1,2,3,4,5]

  p = Pool(processes=2)
  p.map(some_func, some_list)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question