Home  >  Q&A  >  body text

How to efficiently synchronize data in python multi-process or multi-thread?

In multi-threads/multi-processes, tasks can be easily obtained through queue or the like. But when the task is completed, in order to count the number of completed tasks, a value needs to be accumulated.
In the current multi-thread/multi-process situation. I use the lock of the thread/the lock of the manager process of the process to deal with the synchronization problem of counting.
But it feels too inefficient. Not elegant enough.

Is there any better way to handle this?

I feel like this kind of question should be used frequently. Perfect solutions should already exist.
It’s just that I haven’t noticed it yet.

怪我咯怪我咯2685 days ago807

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-06-12 09:26:09

    The problem of inter-process communication can be solved in the way you like (familiar and usable).
    One way is provided below:

    zmq’s pushpull mode
    http://learning-0mq-with-pyzm...

    reply
    0
  • Cancelreply