Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the difference between multiprocessing.sharedctypes.Value and multiprocessing.Value in python

I read the documentation of multiprocessing.Value https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Value

and the documentation of multiprocessing.sharedctypes.Value https://docs.python.org/2/library/multiprocessing.html#multiprocessing.sharedctypes.Value

but couldn't figure out what is the difference between them. do anyone knows? thanks!

like image 248
Elad Lavie Avatar asked Feb 27 '17 16:02

Elad Lavie


People also ask

What is multiprocessing value?

The multiprocessing. Value class is used to share a ctype of a given type among multiple processes. The multiprocessing. Array class is used to share an array of ctypes of a given type among multiple processes. Both the Value and Array classes are aliases for classes in the multiprocessing.

What is multiprocessing Freeze_support?

multiprocessing. freeze_support() This function will allow a frozen program to create and start new processes via the multiprocessing. Process class when the program is frozen for distribution on Windows. If the function is called and the program is not frozen for distribution, then it has no effect.

How do I share data between two processes in Python?

Passing Messages to Processes A simple way to communicate between process with multiprocessing is to use a Queue to pass messages back and forth. Any pickle-able object can pass through a Queue. This short example only passes a single message to a single worker, then the main process waits for the worker to finish.

How does multiprocessing work in Python?

multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads.


1 Answers

In python2.7 at least, Value is simply a wrapper function around sharedctypes.Value, so you'll only notice a difference if you are doing some sort of weird typechecking.

In python3.6, it looks like Value is still just a wrapper around sharedctypes.Value, but it takes care of passing an appropriate context.

like image 93
mgilson Avatar answered Oct 24 '22 16:10

mgilson