Multiprocessing use of cross-platform locks (Windows issues)

Source: Internet
Author: User

Issues that may be encountered on windows that are not turned off by a child process that is turned on

Refer to multiprocessing official documentation:

Explicitly pass resources to child processes

On Unix a child process can make use of a GKFX resource created in a parent process using a global resource. However, it is better to pass the object as a argument to the constructor for the child process.

Apart from making the code (potentially) compatible with Windows This also ensures that as long as the child process is St Ill alive the object is not being garbage collected in the parent process. This might was important if some resource was freed when the object was garbage collected in the parent process.

So for instance

FromMultiprocessingImportprocesslockdef f  (): do something using  "lock" ...< Span class= "K" >if __name__ ==  ' __main__ ' : lock = lock () for i in range (10):  Process (target=f) start ()             

should be rewritten as

FromMultiprocessingImportProcess,LockDefF(L): do something using  "L" ...if __name__ ==  ' __main__ ' : lock = lock () for  I in range (10): process (target=f args= (lock)) start ()             

Multiprocessing use of cross-platform locks (Windows issues)

Related Article

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.