Cross Platform Locking: THe Easy Way
Moshe Zadka
moshez at math.huji.ac.il
Sun Oct 29 09:55:30 EST 2000
OK, here's an easy way to do crossplafrom locking:
Run the following Python script, and then
1) To lock, use urllib to grab the "/lock" url
2) To unlick , use urllib to grab the "/unlock" url
You need to get this to run on system startup.
On UNIX, put it in rc.d.
On NT, do whatever it is NT guys do <wink>
#Released to the public domain by Moshe zadka
import BaseHTTPServer
locked = 0
class LockHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
if self.path=="/lock":
return self.lock()
if self.path=="/unlock":
return self.unlock()
self.send_error(404, "Only locking")
def lock(self):
global locked
if locked:
self.send_error(403, "Already locked")
else:
locked = 1
self.send_response(202)
self.end_headers()
def unlock(self):
global locked
if not locked:
self.send_error(403, "Not locked")
else:
locked = 0
self.send_response(202)
self.end_headers()
def test(HandlerClass = LockHTTPRequestHandler,
ServerClass = BaseHTTPServer.HTTPServer):
BaseHTTPServer.test(HandlerClass, ServerClass)
if __name__ == '__main__':
test()
--
Moshe Zadka <moshez at math.huji.ac.il> -- 95855124
http://advogato.org/person/moshez
More information about the Python-list
mailing list