python-trio / async_generator

Making it easy to write async iterators in Python 3.5
Other
95 stars 23 forks source link

Add support for PEP 525-style garbage collection hooks #15

Closed oremanj closed 6 years ago

oremanj commented 6 years ago

Add async_generator.get_asyncgen_hooks() and async_generator.set_asyncgen_hooks(), and use them under the same circumstances the equivalents in sys would be used for native generators. On 3.6+, the async_generator names refer to the same functions as the sys names, so there's only one set of hooks, and frameworks that use sys.set_asyncgen_hooks() should work seamlessly with async_generator functions as well.

There's an issue with GC ordering or something in pypy, which causes the new logic to make the interpreter segfault under some circumstances, so keep the old logic (which complains if any async_generator is GC'ed before its execution has completed) if we detect that we're running under pypy. The bug has been reported upstream: https://bitbucket.org/pypy/pypy/issues/2786/

codecov[bot] commented 6 years ago

Codecov Report

Merging #15 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #15    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files           7      7            
  Lines         776    972   +196     
  Branches       59     77    +18     
======================================
+ Hits          776    972   +196
Impacted Files Coverage Δ
async_generator/__init__.py 100% <ø> (ø) :arrow_up:
async_generator/_tests/test_async_generator.py 100% <100%> (ø) :arrow_up:
async_generator/_impl.py 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 17521f8...c9168c1. Read the comment docs.

oremanj commented 6 years ago

ping on this?

njsmith commented 6 years ago

Thanks!