[py-dev] greenlet.main_greenlet

Armin Rigo arigo at tunes.org
Sun May 22 16:26:23 CEST 2005


Hi Tom,

On Tue, May 17, 2005 at 10:28:19AM +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:

Unfortunately, this is not thread-safe.  A trick: the main greenlet can
be detected as the one that has no parent:

    greenlet.getcurrent().parent is None

Every thread has its own set of greenlets (including a main one).


A bientot,

Armin


More information about the py-dev mailing list