Re: greenlets and how they can be used

2009-01-05 Thread James Mills
On Tue, Jan 6, 2009 at 4:39 AM, Benjamin Walkenhorst kry...@gmx.net wrote:
 James Mills wrote:
 On Sun, Jan 4, 2009 at 4:52 AM, Benjamin Walkenhorst kry...@gmx.net wrote:
 POE was one of the nicest software frameworks I have ever used, and I've 
 been continuously frustrated by the lack of something like it in other 
 languages such as Python or Ruby.

 It does exist :) It's called circuits.
 Or at least circuits is a framework that I develop
 and build which sounds very similar to POE in
 some ways :)

(snip)
 Then, one very sad day, a Gentoo upgrade broke POE. I got it working again a 
 few months later, but by then I had somehow lost interest in Perl and 
 discovered the beauty of Python, where my search for an appropriate 
 replacement was frustrated (Twisted seemed to be the closest equivalent, but 
 it seemed overly complex to me, at least I never got the hang of it...).

It would seem to me that circuits is quite similar
to POE - I've never really used or played with Perl though
and probably will never :)

 Or, to put it briefly, I would really like to take a look at that sometime. 
 If you intend to release it in any form, I would like to hear about it.

Currently released: circuits-1.0b1

See: http://trac.softcircuit.com.au/circuits/

 Oh. I see, it already IS available. How nice!!! That is going to be an 
 interesting evening!
 Oh, and thank you very much for bringing this to my attention!!!

Your very welcome ... circuits is by no means a replacement
or competitor to Twisted - it has very different design goals
and architecture (nicer/simpler ihmo). That said though anything
that Twisted  can do, circuits can do - I've deliberately tried to
keep the Component Library as simple and straight forward
as possible.

Happy hacking!

cheers
James
--
http://mail.python.org/mailman/listinfo/python-list


Re: greenlets and how they can be used

2009-01-04 Thread James Mills
On Sun, Jan 4, 2009 at 4:52 AM, Benjamin Walkenhorst kry...@gmx.net wrote:
 Back when I was still using Perl, there was - and still is, I guess - a 
 really nice framework called POE, that allowed you to write event-driven 
 state machines in a really easy and pleasant way. Under POE, EVERYTHING was 
 an event. When writing a network server, each incoming client connection was 
 an event, within a connection, each incoming piece of data was an event; when 
 reading a file, each line fired an event (i.e. I/O was completely 
 asynchronous); when querying a database, each result row would fire an event. 
 What was even better, you could very easily plug GTK's or Tk's event loop 
 into the whole mix and have GUI interactions fire events, too.
 POE was one of the nicest software frameworks I have ever used, and I've been 
 continuously frustrated by the lack of something like it in other languages 
 such as Python or Ruby.

It does exist :) It's called circuits.
Or at least circuits is a framework that I develop
and build which sounds very similar to POE in
some ways :)

cheers
James
--
http://mail.python.org/mailman/listinfo/python-list


Re: greenlets and how they can be used

2009-01-03 Thread Mark Wooding
James Mills prolo...@shortcircuit.net.au wrote:

 The greenlet from http://codespeak.net/py/dist/greenlet.html
 is a rather interesting way of handling flow of control.

Ahh, yes.  It's actually a rather old idea, but too rarely used.

 What can greenlet's be used for ? What use-cases have you guys used
 them for (if any) ?

I've one project in which I use coroutines (either greenlets or some
coroutines I concocted out of Python's built-in threading) extensively.
The system consists of a server which speaks a text-based protocol
(written in C), a graphical monitor program, and a number of ancillary
services which are both clients of the server, and augment it by
providing additional commands.  The monitor and the services are all in
Python, and make extensive use of coroutines.

One reason for this is that some of the server's commands can take a
long time, so it's useful for the programs to be able to do other things
while they wait for replies.  Full-on threading would be possible, but
(a) in fact I make a /lot/ of coroutines, and (b) with coroutines I
don't have to think anywhere near as hard about synchronization.

You can browse about here, if you like:

  http://git.distorted.org.uk/gitweb/~mdw/tripe?a=tree;h=python

The main Python module is in py/; the services are in svc/, and the
graphical monitor is in mon/.

 Can they be used in place of threads with much the same effect - but
 more lightweight ?

More lightweight, and much easier to reason about.  They also confuse
other libraries less.

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list


Re: greenlets and how they can be used

2008-12-31 Thread Aaron Brady
On Dec 30, 9:40 pm, James Mills prolo...@shortcircuit.net.au
wrote:
 Hey all,

 The greenlet fromhttp://codespeak.net/py/dist/greenlet.html
 is a rather interesting way of handling flow of control.

 I can't seem to find anything else on the subject
 except for the above link and the most recent version
 0.2 and it's tests.

 What can greenlet's be used for ? What use-cases
 have you guys used them for (if any) ?

 Can they be used in place of threads with much
 the same effect -  but more lightweight ?

I don't know Erlang, but it seems to be useful for a construction of a
unit of work that is more consistent with the underlying goal.

I had a dream for a while that in a GUI framework, every event would
spawn a unique thread.  The GUI would remain responsive even while
executing minor tasks.  Of course, shaving a second off running time
isn't exactly mission-critical to GUI users.
--
http://mail.python.org/mailman/listinfo/python-list


Re: greenlets and how they can be used

2008-12-31 Thread James Mills
On Thu, Jan 1, 2009 at 9:24 AM, Aaron Brady castiro...@gmail.com wrote:
(snip)

 I had a dream for a while that in a GUI framework, every event would
 spawn a unique thread.  The GUI would remain responsive even while
 executing minor tasks.  Of course, shaving a second off running time
 isn't exactly mission-critical to GUI users.

Do you think greenlet's (this implementation anyway)
would be useful in circuits (1) ? When you say every
even that was created would spawn a new thread
or greenlet ... Makes me wonder ... Just a thought ...
What's yours ?

cheers
James

1. http://trac.softcircuit.com.au/circuits/
--
http://mail.python.org/mailman/listinfo/python-list