supporting asyncronous messages

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Mar 7 04:48:32 EST 2001


Joshua Spoerri <josh at pobox.com> writes:

> for example:
> 	a = wfmessage()
> 	b = wfmessage()
> 	a.send()
> 	b.send()
> 	if a.getResponse() || b.getResponse():
> 	whatever
> 
> If b.getResponse() is already available and true,
> but a.getReponse() is blocking, the program shouldn't
> wait for it. (Yes, this does funny things to
> shortcircuiting order.)
> 
> Is there a sane way to support this behaviour without
> hacking up the compiler? Is it bad news for other
> reasons?

Sure. The "design pattern" being used is the same as in select
(reactor):

ready = reactor.pick_one([a,b], timeout)

Then you have delegated the blocking business into pick_one, where you
have a number of options: busy-waiting, multi-threading, the operating
system's select/WaitForMultipleObjects mechanism, and perhaps others -
it much depends on how getResponse does its blocking.

Regards,
Martin



More information about the Python-list mailing list