Re: Non-blocking publishing in Python

[email protected] Wed, 6 Apr 2005 22:44:27 -0500
Newsgroups gmane.comp.web.mod-pubsub.devel
Message-ID <[email protected]>
A:

> xmlBlaster and Activ MQ's HTTP for asynchronous notification either
> require polling or a proxy that can accept connections across the
> firewall. The beauty (and scariness) of mod-pubsub's approach is the
> use of streaming HTTP to keep connections persistent so no polling and
> no proxy needed.


At what level of granularity is polling not required? The reason I ask is=
 that
the Python pubsublib client very much uses polling:

    while 1:
        asyncore.poll(scheduler.timeout())
        # print "\n\n asyncore.poll \n"
        scheduler.run()

Going back to the original question I had, this is the core of the proble=
m since
the while loop is very much blocking and is processor intensive. From the
original Medusa documentation on asyncore, I offer the following quote:

"Now that you know what select() does, you're ready for the final piece o=
f the
puzzle: the main polling loop. This is nothing more than a simple while l=
oop
that continually calls select() with a timeout (I usually use a 30-second
timeout). Such a program will use virtually no CPU if your server is idle=
; it
spends most of its time letting the operating system do the waiting for i=
t.
This is much more efficient than a busy-wait loop."

Hence the solution was to do just this: replace the while loop with the l=
oop()
command which is much more CPU-friendly.

  asyncore.loop()

Anyone interested in embedding the client in a larger python project will=
 likely
need to do this. Ultimately, this is a more efficient implementation and =
should
probably be merged into the code base. Do you want a patch?

Brian

--=20
  =3D=3D=3D=3D
brian lee dae yung
biomimetic art and research
  mux space . com

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=3D6595&alloc_id=3D14396&op=3Dclick