Wiki

Clone wiki

greenlet / Home

Limitations

  • Live greenlets won't be garbage collected if they are captured in most of the places on C stack.
    • Function arguments: if you pass greenlets as arguments and especially as keyword arguments to a function, cycles with that greenlet cannot be garbage collected while that function is running. There's one exception: when greenlet is passed as a positional argument to its startup function.
    • Bound methods: e.g. getcurrent().parent.switch() produces a bound method with reference to the parent greenlet and that bound method is held on C stack until greenlet returns from switch().
    • Bound methods: another huge gotcha is if you subclass greenlet and define a 'run' method: while that bound method is executing greenlet cannot be garbage collected.

TODO

  • Figure out ways to work around these limitations, where possible.
    • Bound methods are a priority, subclassing greenlet is very common and no live gc with those is a show stopper.
  • Is kill_greenlet's assumption about being impossible to be ts_current's parent still correct? If not, greenlet needs to be spliced out of ts_current's parent chain.

Updated