Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.060 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'below)': 0.09; 'forcing': 0.09; 'ping': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; 'true:': 0.16; 'finished': 0.19; 'import': 0.22; '(by': 0.24; 'skip:l 30': 0.24; 'question': 0.24; '(see': 0.26; 'task': 0.26; 'defined': 0.27; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'correctly.': 0.31; 'prints': 0.31; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; '8bit%:9': 0.36; 'done,': 0.36; 'yield': 0.36; 'hi,': 0.36; 'skip:& 10': 0.38; 'tasks': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'new': 0.61; 'from:charset:utf-8': 0.61; 'simple': 0.61; '8bit%:10': 0.64; 'of:': 0.68; 'behavior': 0.77; 'launches': 0.84; 'increases': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=s8mPicURz/ONAWOBlqXs3hh1GX/3t2YUnBRF9siTI1s=; b=UDS+1IsgyGAvgxDinhYjuLhSrXxdHG+FeGwszGQaRGSsd0YXK2d/VIaCBwJ00R+/+8 /b+8XOrAAUa90gPVrQZSmszQKZ3Lv4HXVrbsep3NX0Oo2R6GHX8F5UrA1tLl3y2A/7nS p4AN/jwPyPhJwRV89bKLyXSel03RfbujhH0d6T21vh9y4pdP8mP6agdv+ypkLQhNv0Zr DNJK/oFm93RNyQMnKDE6aVK6hMYTiutf3V9AX/U7gyv0EIXzuRyQVI+YtaB5e+tVJXL/ 9zNrvmOTUs0PvZxBx91JuLQ9yRFL3daCszMwmJxPlIIwKvNv9MAAp0VG7vSdOqdpnpjp n4tw== MIME-Version: 1.0 X-Received: by 10.202.3.65 with SMTP id 62mr14461915oid.11.1427445207414; Fri, 27 Mar 2015 01:33:27 -0700 (PDT) Date: Fri, 27 Mar 2015 01:33:27 -0700 Subject: asyncio From: =?UTF-8?Q?=C5=81ukasz_Ligowski?= To: python-list@python.org Content-Type: multipart/alternative; boundary=001a113ba080863eb9051240fc71 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 96 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427445210 news.xs4all.nl 2852 [2001:888:2000:d::a6]:40383 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88141 --001a113ba080863eb9051240fc71 Content-Type: text/plain; charset=UTF-8 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: 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() --001a113ba080863eb9051240fc71 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 lau= nches (by loop.create_task()) simple task that waits some and prints "= ping".
Question is why finished "ping" tasks keep accumul= ating in Task.all_tasks? After a while there is a lot of:
&l= t;Task finished coro=3D<ping() done, defined at test.py:25> result=3D= 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

imp= ort asyncio

loop =3D asyncio.get_event_loop()

@asyncio.coroutine
def print_tasks(loop):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 while True:
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 tasks =3D asyncio.Task.all_tasks(loo= p)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 for task in tasks:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 print(task)
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 print()

=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 yield fr= om asyncio.sleep(1)

@asyncio.coroutine
d= ef task_launcher(loop):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 while True:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 yield from= asyncio.sleep(1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 loop.create_task(ping())

@asyncio.corou= tine
def ping():
=C2=A0 =C2=A0 =C2=A0 =C2=A0 yield from= asyncio.sleep(2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 print("ping&qu= ot;)


loop.create_task(print_tasks(l= oop))
loop.create_task(task_launcher(loop))

<= div>loop.run_forever()

--001a113ba080863eb9051240fc71--