Multiprocessing for write and read file

Hi all,

I’m programming a python based software which uses multiprocessing technique. For one process, it will call “itk.ImageFileWrite” to export a 3D volume to a NRRD file (“write” operation). For the rest processes, they will call “itk.ImageFileRead” to get voxel values from this NRRD file (“read” operation). My question is how to know whether the “write” operation has completed before a “read” operation, otherwise, “read” operation for some processes will fail because the NRRD file is still in writing in one process, although I think the time difference is less than 1 second. Any suggestion are welcome.

Regards,

Zhuangming Shen

Protect the file using a mutex (possibly called a lock in Python). The writing thread acquires the lock before it starts writing, and releases it once it is finished. More in this SO thread.

@dzenanz Thanks for your response.