Python - appending to same file from multiple threads

后端 未结 3 1328
一个人的身影
一个人的身影 2020-12-02 14:19

I\'m writing an app that appends lines to the same file from multiple threads.

I have a problem in which some lines are appended without a new line.

Any solu

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 15:03

    And maybe some more newlines where they shouldn't be?

    You should have in mind the fact that a shared resource should not be accessed by more than one thread at a time or otherwise unpredictable consequences might happen (it's called using 'atomic operations' while using threads).

    Take a look at this page for a little intuition: Thread Synchronization Mechanisms in Python

提交回复
热议问题