SoFunction
Updated on 2024-10-29

Python implementation guarantees that only one instance of a script can be run

'''
    @(func)
    def f(*args,**kwargs):
        import socket
        try:
# global attribute, otherwise the variable is destroyed after the method exits
            global s
            s = ()
            host = ()
            ((host, 60123))
        except:
            print('already has an instance')
            return None
        return func(*args,**kwargs)
    return f
[code]
Used on the main function of a script:
[code]
@just_one_instance
main():
    do sth.