Python multiprocessing doesn't play nicely with uuid.uuid4()

坚强是说给别人听的谎言 提交于 2019-12-05 07:22:46

This is the correct way to generate your own uuid4, if you need to do that:

import os, uuid
return uuid.UUID(bytes=os.urandom(16), version=4)

Python should be doing this automatically--this code is right out of uuid.uuid4, when the native _uuid_generate_random doesn't exist. There must be something wrong with your platform's _uuid_generate_random.

If you have to do this, don't just work around it yourself and let everyone else on your platform suffer; report the bug.

I dont see a way to make this work either. But you could just generate all the uuids in the main thread and pass them to the workers.

This works fine for me. Does your Python installation have os.urandom? If not, random number seeding will be very poor and would lead to this problem (assuming there's also no native UUID module, uuid._uuid_generate_random).

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