2 daemons write to a single file /w python file IO

Discussion in 'Python' started by Andrey, Sep 12, 2007.

  1. Andrey

    Andrey Guest

    HI

    i have a newbie question about the file() function.
    I have 2 daemons running on my linux box.

    1 will record the IDs to a file - logs.txt
    other 1 will open this file, read the IDs, and then "Clean up the
    file" -logs.txt

    Since these 2 daemons will run every 2-5mins, I think this will crash, isn't
    it? When both daemons try to write to the file at the same time.

    I am wondering if this won't crash, OR if there is some simple high-level
    functions can lock the file while writing...
    I also wonder if one side locked the file, what happens if the other side
    try to open this locked file? raise error? so i also need to write a loop to
    wait for the file to release locking?

    seems a basic easy thing but i just cannot find an simple answer.
    I always advoid this issue by putting them in mysql (well, fast and hassle
    free for locking)

    Thanks
    Jay
     
    Andrey, Sep 12, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    447
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Sep 13, 2006
  2. Steven W. Orr
    Replies:
    0
    Views:
    443
    Steven W. Orr
    Sep 14, 2007
  3. PurpleServerMonkey

    Python, Daemons and D-Bus

    PurpleServerMonkey, May 24, 2008, in forum: Python
    Replies:
    3
    Views:
    355
    Diez B. Roggisch
    May 25, 2008
  4. Jeffrey Barish

    Single-instance daemons

    Jeffrey Barish, Nov 12, 2008, in forum: Python
    Replies:
    5
    Views:
    439
    Дамјан ГеоргиевÑки
    Nov 17, 2008
  5. Junkone
    Replies:
    1
    Views:
    219
    Kevin Williams
    Feb 16, 2008
Loading...

Share This Page