Python Basic Learning Log day10-inter-process data communication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.