[Python-Dev] Withdrawn PEP 288 and thoughts on PEP 342

Gustavo J. A. M. Carneiro gjc at inescporto.pt
Fri Jun 17 12:29:49 CEST 2005


  Hello,

  I found your paper very interesting.  I have also written a very
minimalistic white paper, mostly aimed at the PyGTK community, with a
small module for pseudo-threads using python generators:

	http://www.gnome.org/~gjc/gtasklet/gtasklets.html

  I don't have time to follow this whole discussion, but I leave it here
as another example of python pseudo-threads.  I also am very much in
favour of having yield receive return values or exceptions, as this
would make pseudo-threads much more elegant.  And I very much wish
python had this builtin or in std library.

  In conjunction with pseudo-threads, I think a "python main loop"
implementation is fundamental. Such main loop with permit the programmer
to  register callbacks for events, such as timeouts, IO conditions, idle
tasks, etc., such as one found glib (gtk+'s underlying library).  I
already pointed out one such implementation that I use for one of my
projects, and it already has unit tests to prove that it works.

  This is also related to the "deprecate asyncore/asynchat" discussions
going on earlier.  IMHO, they should really be deprecated, and a
pseudo-threads solution could be used instead.

  Anyway, I'd love to help more in this area, but unfortunately I don't
have time for these endless discussions... :P

  Best regards.


On Fri, 2005-06-17 at 10:12 +0100, Michael Sparks wrote:
> At 08:24 PM 6/16/2005 -0400, Raymond Hettinger wrote:
> > As a further benefit, using
> >attributes was a natural approach because that same technique has long
> >been used with classes (so no new syntax was needed and the learning
> >curve was zero).
> 
> On Friday 17 Jun 2005 02:53, Phillip J. Eby wrote:
> > Ugh.  Having actually emulated co-routines using generators, I have to tell
> > you that I don't find generator attributes natural for this at all;
> > returning a value or error (via PEP 343's throw()) from a yield expression
> > as in PEP 342 is just what I've been wanting.
> 
> We've been essentially emulating co-routines using generators embedded
> into a class to give us the equivalent of generator attributes. We've found
> this very natural for system composition. (Essentially it's a CSP type system, 
> though with an aim of ease of use)
> 
> I've written up my talk from ACCU/Python UK this year, and it's available
> here: http://www.bbc.co.uk/rd/pubs/whp/whp113.shtml
> 
> I'll also be talking about it at Europython later this month.
> 
> At 08:03 PM 6/16/2005 -0700, Guido van Rossum wrote:
> >Someone should really come up with some realistic coroutine examples
> >written using PEP 342 (with or without "continue EXPR").
> 
> On Friday 17 Jun 2005 05:07:22, Phillip J. Eby wrote:
> > How's this?
> > 
> >    def echo(sock):
> >        while True:
> >            try:
> >                data = yield nonblocking_read(sock)
> >                yield nonblocking_write(sock, data)
> ... snip ...
> 
> For comparison, our version of this would be:
> 
> from Axon.Component import component
> from Kamaelia.SimpleServerComponent import SimpleServer
> class Echo(component):
>    def mainBody(self):
>       while True:
>          if self.dataReady("inbox"):
>             self.send(data,"outbox")
>          yield1
> 
> SimpleServer(protocol=EchoProtocol, port=1501).run()
> 
> 
> For more interesting pipelines we have:
> 
> pipeline(TCPClient("127.0.0.1",1500),
>          VorbisDecode(),
>          AOAudioPlaybackAdaptor()
>         ).run()
> 
> Which works in the same way as a Unix pipeline. I haven't written the 
> "pipegraph" or similar component yet that could allow this:
> 
> graph(A=SingleServer("0.0.0.0", 1500),
>            B=Echo(),
>            layout = { "A:outbox": "B:inbox", "B:outbox" : "A:inbox" } )
> 
> (Still undecided on API for that really, currently the above is a lot more 
> verbose -)
> 
> By contrast I really can't see how passing attributes in via .next() helps 
> this approach in any way (Not that that's a problem for us :).
> 
> I CAN see though it helps if you're taking the approach for generator
> composition if you're using twisted.flow (though I'll defer a good example
> for that to someone else since although I've been asked for a comparison in 
> the past, I don't think I'm sufficiently twisted to do so!). 
> 
> 
> Michael.
-- 
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
The universe is always one step beyond logic.



More information about the Python-Dev mailing list