top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Global Variable In Multiprocessing with Python

+2 votes

Please share some thoughts of Global Variable In multiprocessing with examples for python.
Do we have some best practices of multiprocessing.

posted Oct 23, 2013 by Sanketi Garg

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

Fundamentally, you can't have mutable globals in multiprocessing (though you can have immutables - they'll get copied into each subprocess). Instead, look into the various data structures like the queue, which can transfer information from one process to another. The best option depends a lot on what you're doing - but you can find some tips and ideas in the multiprocessing module's documentation.

answer Oct 23, 2013 by Bob Wise
Similar Questions
+1 vote

Please share your idea about Multiprocessing and Multithreading specially in context of python.

0 votes

I need a command that will make threads created by "multiprocessing.Process()" wait for each other to complete. For instance, I want to do something like this:

job1 = multiprocessing.Process(CMD1())
job2 = multiprocessing.Process(CMD2())

jobs1.start(); jobs2.start()


The command "PY_FUNC()" depends on the end result of the actions of CMD1() and CMD2(). I need some kind of wait command for the two threads that will not let the script continue until job1 and job2 are complete. Is this possible in Python3?

+2 votes

Is it possible to have a default dictionary where the default is dependent on the key?

I was hoping something like this might work:

>>> m = defaultdict(lambda key: key+1)

But it obviously doesn't:

>>> m[3]

Traceback (most recent call last):

 File "", line 1, in 
TypeError: () takes exactly 1 argument (0 given)
+2 votes

In multi-processor system it is possible that 2 core's trying to modify same memory, then who takes care of it? - MMU/OS?
And, in single processor but multi-core system who takes care of it? - CPU itself or MMU/OS?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.