0
  1. From the main process, I create 3 child processes and I pass an instance of a 'common' class...the same instance is passed to all 3 child processes.
  2. This common class has a dictionary and a queue (which contains a lot of items)
  3. These child processes retrieve 'items' from this queue
  4. For these items, I call a REST service to get some data about the 'item'
  5. I add this info to the "common" dictionary
  6. There are no errors

However, when I try to access this dictionary from the main process, its empty.

user2097496
  • 267
  • 3
  • 10

2 Answers2

0

For sharing state between processes, the most flexible way is to use a multiprocessing.Manager. You can also use e.g. multiprocessing.Array, but that can only contain data of the same type.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
0

Thanks for your responses.

I managed to solve the problem using multiprocessing.Manager().dict()

Is this the best way....I'm not entirely sure. I think I need to read a lot more on Multiprocessing.

What I find challenging is the fact that the multiprocessing module offers a lot of functionality and as a beginner, its quite challenging to know the right 'tools' to use for the job.

I started off with threads...then moved to Processes....then used Queues....then used Managers. But as I read more on this subject, I see Python has a lot more to offer.

user2097496
  • 267
  • 3
  • 10