[py-dev] greenlet.main_greenlet

Armin Rigo arigo at tunes.org
Sat Aug 27 18:31:00 CEST 2005


Hi Tom,

On Tue, May 17, 2005 at 10:15:00AM +0530, Tom Locke wrote:
> I had a need to be able to test if the current greenlet was the main 
> greenlet. I figured this might be something that crops up now and again, 
> so I added a module attribute `main_greeenlet` (also copied to the type 
> object), so I can just test for:
> 
>    greenlet.getcurrent() == greenlet.main_greenlet

This won't work in a multithreaded application, because each thread has
its own main greenlet.  Instead, just check if greenlet.getcurrent() has
a parent or not.  All greenlets have a parent apart from the main one.


Armin


More information about the py-dev mailing list