Objective:
When using multiple processes with tornado, multiple processes are required to share a state variable, so consider using multiprocessing. Value(please refer to the relevant information for the specific details of the variable). In the use of value on the Internet, because the share is a string, but the introduction of the Internet is an integer or character, so encountered a lot of obstacles, through the search official documents to obtain a solution.
First, the value of the constructor:
the initialization of value is very simple, just like The Value(' d ', 0.0) can be constructed by:
multiprocessing.
value
typecode_or_type , *args [,  lock ]).
< Span class= "p" > This method returns a < Span class= "Pre" >ctypes
object, Defines the type of return. It is either a ctypes type or a code that represents the cTYPES type. For example c_bool and ' B ' are the same, because ' B ' is c_bool code.
cTYPES is an external library of Python that provides data types that are part of the C language and can call DLLs or shared library functions that can be used to wrap these libraries in Python.
*args is a construction parameter passed to the cTYPES
Second, the use of value
For shared integers or single characters, initialization is simpler and reference mappings can be done. such as I = value (' i ', 1), c = value (' C ', ' 0 ').
Note that if the code we use does not exist on the above table, it will be thrown:
Size = ctypes.sizeof (type_)
Typeerror:this type has no size
If you are sharing a string, you cannot find a mapping relationship in the table above, or no code is available. So we need to use the original CType type
For example
From ctypes import c_char_p
SS = Value (c_char_p, ' SS ')
CType types are available from the table below
Python multi-process shared variable value using tips