Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88141
| Date | 2015-03-27 01:33 -0700 |
|---|---|
| Subject | asyncio |
| From | Łukasz Ligowski <orangewarrior@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.237.1427445210.10327.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
Hi,
I wrote simple asyncio program (see below) and I'm not sure if I understand
behavior correctly.
I have print_tasks coroutine which prints each task in a loop by using
Task.all_tasks function.
I have also task_launcher coroutine that launches (by loop.create_task())
simple task that waits some and prints "ping".
Question is why finished "ping" tasks keep accumulating in Task.all_tasks?
After a while there is a lot of:
<Task finished coro=<ping() done, defined at test.py:25> result=None>
when printing in Task.all_tasks and number of those increases as new ping
tasks are launched
Is there a way to prune finished tasks (I tried forcing gc) or I do
something wrong?
I ran on python 3.4.3.
Best regards,
L
import asyncio
loop = asyncio.get_event_loop()
@asyncio.coroutine
def print_tasks(loop):
while True:
tasks = asyncio.Task.all_tasks(loop)
for task in tasks:
print(task)
print()
yield from asyncio.sleep(1)
@asyncio.coroutine
def task_launcher(loop):
while True:
yield from asyncio.sleep(1)
loop.create_task(ping())
@asyncio.coroutine
def ping():
yield from asyncio.sleep(2)
print("ping")
loop.create_task(print_tasks(loop))
loop.create_task(task_launcher(loop))
loop.run_forever()
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
asyncio Łukasz Ligowski <orangewarrior@gmail.com> - 2015-03-27 01:33 -0700
Re: asyncio Marko Rauhamaa <marko@pacujo.net> - 2015-03-27 10:55 +0200
Re: asyncio orangewarrior@gmail.com - 2015-03-27 02:32 -0700
Re: asyncio Marko Rauhamaa <marko@pacujo.net> - 2015-03-27 14:38 +0200
Re: asyncio Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-27 08:15 -0600
Re: asyncio Marko Rauhamaa <marko@pacujo.net> - 2015-03-27 17:44 +0200
Re: asyncio Marko Rauhamaa <marko@pacujo.net> - 2015-03-27 17:52 +0200
Re: asyncio orangewarrior@gmail.com - 2015-03-27 16:27 -0700
csiph-web