Posted By

manatlan on 10/20/09


Tagged

socket python tech


Versions (?)

simple lock application with socket / port


 / Published in: Python
 

  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  

You need to login to post a comment.