2

Why does this work:

>>> import greenlet
>>> greenlet.getcurrent()
<greenlet.greenlet object at 0x02244030>

I haven't started any greenlets yet, so what is getcurrent() returning? Is there a 'default greenlet' that gets run when I import the package? Or is this just the 'greenlet representation' of my current program stack.

amwinter
  • 3,121
  • 2
  • 27
  • 25

1 Answers1

1

It returns the "main greenlet", which indeed is just a representation of the main program outside any other explicit greenlet.

Armin Rigo
  • 12,048
  • 37
  • 48
  • when is the main greenlet created? – amwinter Jun 09 '13 at 09:41
  • 1
    It doesn't matter, but it is created lazily when you first ask for it. The reason it is created lazily is that there is actually one per thread, not just one globally. But you should think about them as created at the time the program started (or at the time a new thread started). – Armin Rigo Jun 09 '13 at 14:12
  • ah, I see it -- `green_create_main` in the C file – amwinter Jun 09 '13 at 20:13