What happens if I log into the same file from multiple different processes in python?

后端 未结 3 2247
礼貌的吻别
礼貌的吻别 2021-02-15 11:36

I spent hours to dig the behavior, first about those questions:

  • Atomicity of `write(2)` to a local filesystem
  • How can I synchronize -- make atomic -- writ
3条回答
  •  梦毁少年i
    2021-02-15 11:56

    I have tried a similar code like this(I have tried in python 3)

    import threading
    for i in range(0,100000):
         t1 = threading.Thread(target= funtion_to_call_logger, args=(i,))
         t1.start()
    

    This worked completely fine for me, similar issue is addressed here.

    This took a lot of Cpu time but not memory.

    EDIT:
    Fine means all the requested things were logged but Order was missing.Hence Race condition still not fixed ,

提交回复
热议问题