simple lock application with socket / port


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import socket
  2.  
  3. class Lock:
  4. _s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5. @classmethod
  6. def isPresent(cls,p=77777):
  7. try:
  8. cls._s.bind(("localhost", p))
  9. cls._s.listen(1)
  10. return False
  11. except:
  12. return True
  13.  
  14. if Lock.isPresent():
  15. print "is running"
  16. else:
  17. print "run"
  18. import time
  19. time.sleep(10)
  20. print "end"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.