New submission from Eric Appelt:

While testing my understanding in order to document PEP525 asynchronous 
generators in the Language Reference (issue 28091) I noticed that the 
implemented behavior deviates from PEP525, specifically the PEP states that:

"When an asynchronous generator is iterated for the first time, it stores a 
reference to the current finalizer. If there is none, a RuntimeError is raised. 
This provides a strong guarantee that every asynchronous generator object will 
always have a finalizer installed by the correct event loop."

I created an asynchronous generator to try to run calling __anext__ 
interactively without an event loop to check the behavior, and was surprised 
when I didn't get a RuntimeError even though I had not called 
sys.set_asyncgen_hooks() to set a finalizer function.

I looked at the function async_gen_init_hooks defined in Objects/genobject.c 
and it appears that if the thread state async_gen_finalizer is NULL, then it 
just returns zero and allows the calling function to continue.

I'm not sure if this is a bug, or this is intentional and the finalizer 
mechanism should be optional. If it is the latter should PEP525 get updated?

----------
components: Interpreter Core
messages: 282737
nosy: Eric Appelt, yselivanov
priority: normal
severity: normal
status: open
title: Async generator does not raise RuntimeError if finalizer not set
type: behavior
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28910>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to