1

Several processes are each writing a file to a directory. The goal is to control the size of the directory such that whenever it reaches a size (S), all processes stop writing to the directory and discard the file they are about to write.

If the size then becomes lower than S because some of those files were removed, the processes will resume writing files.

It seems that I need inter-process locking to achieve this design. However, I thought maybe there's an easier way, since inter process locking is not readily available in python and obviously there's contention between processes.

Python 2.7 Platforms (Win, Mac, Linux)

4

1 回答 1

1

使用锁定文件可能是一种选择。例如,每个进程在写入之前都会检查诸如“/target_dir/lock”之类的文件。如果文件存在,进程将不会写任何东西。所以你必须运行单独的监视器进程,它检查目录大小,并创建或删除锁定文件。

于 2014-01-21T16:28:08.023 回答