Skip to content

adjunct.singleton

MutexError

Bases: Exception

Failed to lock a file.

mutex(filename)

Lock a mutex file.

This can be used to prevent scripts from having more than one instance of themselves running at the same time as follows:

if __name__ == "__main__":
    with mutex(__file__):
        main()

Parameters:

Name Type Description Default
filename str

path of the file to lock

required