Help Create Good Data Model

fumanchu fumanchu at amor.org
Mon Mar 13 01:07:52 CET 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