Return to Snippet

Revision: 19269
at October 20, 2009 05:23 by manatlan


Initial Code
import socket

class Lock:
    _s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    @classmethod
    def isPresent(cls,p=77777):
        try:
            cls._s.bind(("localhost", p))
            cls._s.listen(1)
            return False
        except:
            return True

if Lock.isPresent():
    print "is running"
else:
    print "run"
    import time
    time.sleep(10)
    print "end"

Initial URL

                                

Initial Description

                                

Initial Title
simple lock application with socket / port

Initial Tags
python

Initial Language
Python