This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Example in asyncio task gives resource warning
Type: resource usage Stage: resolved
Components: Documentation Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, python-dev, vajrasky, vstinner
Priority: normal Keywords: patch

Created on 2014-02-17 06:33 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
shut_off_resource_warning_run_forever_asyncio_example.patch vajrasky, 2014-02-17 06:35 review
Messages (4)
msg211392 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-02-17 06:33
From http://docs.python.org/3.4/library/asyncio-task.html#example-future-with-run-until-complete

there is an example code:
import asyncio

@asyncio.coroutine
def slow_operation(future):
    yield from asyncio.sleep(1)
    future.set_result('Future in done!')

def got_result(future):
    print(future.result())
    loop.stop()

loop = asyncio.get_event_loop()
future = asyncio.Future()
asyncio.Task(slow_operation(future))
future.add_done_callback(got_result)
loop.run_forever()


I got this:
ethan@amiau:~/Documents/code/python/cpython3.4$ ./python /tmp/demo.py
Future in done!
sys:1: ResourceWarning: unclosed <socket object at 0x7feb49df1058>
sys:1: ResourceWarning: unclosed <socket object at 0x7feb493b48c8>

Here is the patch to shut off the resource warning.
msg211393 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-02-17 06:35
The patch also fixed some typos.

s/Future in done/Future is done/
msg211403 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-17 09:56
New changeset ea4c74cc4da5 by Victor Stinner in branch 'default':
Close #20652: asyncio doc: close the event loop in run_forever() example. Fix
http://hg.python.org/cpython/rev/ea4c74cc4da5
msg213803 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-17 06:30
New changeset 36005fe2ab9b by Victor Stinner in branch '3.4':
Close #20652: asyncio doc: close the event loop in run_forever() example. Fix
http://hg.python.org/cpython/rev/36005fe2ab9b
History
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64851
2014-03-17 06:30:47python-devsetmessages: + msg213803
2014-02-17 09:56:13python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg211403

resolution: fixed
stage: resolved
2014-02-17 06:35:04vajraskysetfiles: + shut_off_resource_warning_run_forever_asyncio_example.patch

messages: + msg211393
2014-02-17 06:34:32vajraskysetfiles: - shut_off_resource_warning_run_forever_asyncio_example.patch
2014-02-17 06:33:22vajraskycreate