Synchronization issue using Python's multiprocessing module

大城市里の小女人 提交于 2019-12-06 10:02:25

Because the whole point of multiprocessing is parallelism. Your processes are running at the same time as each other, so they may actually start and finish in any order.

The lock acquisition only ensures that they don't try to print at the same time - but that lock may be acquired by the various processes in any random order. It's more likely to be acquired by the first process you create, because that process will go through its initialization sooner and thus likely be the first one to request the lock. But there's no guaranteed of the order.

It depends on how the OS schedules which one runs first, and your lock only prevents more than one of them running at the same time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!