One: Inter-process data exchange method
The memory between the different processes is not shared, in order to realize the data exchange between two processes, the following methods can be used:
1) queue, using the same method as the threading queue
#-*-coding:utf-8-*-__author__='Shisanjun' fromMultiprocessingImportProcess,queueImportThreadingImportQueue#def run (q):#Q.put ([42,none, "Hello"])###if __name__== "__main__":##Q=queue ()#p=process (target=run,args= (q,))#P.start ()#print (Q.get ())"""transfer between normal processes, the query as a parameter to the child process want to when the parent process to clone a copy of the data to the child process the other is two Q parent process Q serialization is saved in a location, the sub-process Q is deserialized"""deff (): Q.put ([42,none,"Hello"])#if __name__== "__main__":##Q=queue. Queue ()#p=threading. Thread (target=f,)#P.start ()#print (Q.get ())"""threads share memory, so you can access the Q"""#if __name__== "__main__":##Q=queue. Queue ()#p=process (target=f,)#P.start ()#print (Q.get ())"""the name ' Q ' is not defined the main process and the child process cannot share memory, so you cannot use the Q"""if __name__=="__main__": Q=queue. Queue ()#Thread QueueP=process (target=f,args=(q,)) P.start ()Print(Q.get ())"""typeerror:can ' t pickle _thread.lock objects The data in the thread, he's not serializing, putting the data in the process"""
Python Basic Learning Log day10-inter-process data communication