[Python] Django lock a file to prevent concurrent access

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new at Django, just wondering how can we lock a file in Django, when concurrent users want to edit a file? I use the django.cores.files.locks but it doesn't work

    This is what I did:

    with open(filename,"r+") as f:
    locks.lock(f, locks.LOCK_EX)
    f.write(input_text.encode(utf-8))
    # ... some processing
    locks.unlock(f)
    f.close


    anyone has an idea?

    Cheers,

    Continue reading...

Compartilhe esta Página