Python multiple threads accessing same file

后端 未结 3 1214
小蘑菇
小蘑菇 2021-01-04 05:52

I have two threads, one which writes to a file, and another which periodically moves the file to a different location. The writes always calls open before writi

3条回答
  •  感动是毒
    2021-01-04 06:29

    When two threads access the same resources, weird things happen. To avoid that, always lock the resource. Python has the convenient threading.Lock for that, as well as some other tools (see documentation of the threading module).

提交回复
热议问题