Help Create Good Data Model
fumanchu
fumanchu at amor.org
Sun Mar 12 19:07:52 EST 2006
If you used a Queue, it wouldn't be the container itself; rather, it
would be a gatekeeper between the container and consumer code. A
minimal example of user-side code would be:
class Request:
def __init__(self, op, data):
self.op = op
self.data = data
self.reply = None
req = Request('get', key)
data_q.put(req, block=True)
while req.reply is None:
time.sleep(0.1)
do_something_with(req.reply)
The container-side code would be:
while True:
request = data_q.get(block=True)
request.reply = handle(request)
That can be improved with queue timeouts on both sides, but it shows
the basic idea.
Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list