Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.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.052 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'that?': 0.05; 'subject:application': 0.07; 'wrapped': 0.09; 'pil.': 0.16; 'code.': 0.18; 'file.': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'getting': 0.31; 'anyone': 0.31; 'figure': 0.32; 'supposed': 0.32; 'skip:t 40': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'should': 0.36; 'wrong': 0.37; 'tasks': 0.38; 'to:addr:python-list': 0.38; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:a 30': 0.61; 'from:charset:utf-8': 0.61; 'therefore,': 0.64 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=MNq6JDHfmQ++h4YRN+jq/T5y2Wf+sKkGh1QrqsOPoRs=; b=S+6uqDLeZfpNkkZzXIZYHFywG6wW43Bevn1Ppo5JW+wih1eNB8KjZRotAtOv7sN4ij JUcbbQswPdDllqLN3lNMSGK+s9SemzFx8jzVgxtMDL340F7RkDde75z2kjKT3FVxbbC5 8oQVJYpuRHTU47JBDYx994h+Y6nVxTDfRvXfBDLB73762s42Jp5e+KZgl5tTX6/KCyKY jHufzH6ZMo/wD6lAwoStDxLSDEPCVfQP9R9o0lPEew4qc/BEzIs/qsxq0bwZy8Oz03/W FDbU0u2LYvZ3OBSUEEpFI2mu/ZtxPdNjZElEvcYSO3CwsP9VVNYwyz9O6RWmS/9XIxIs 3CJg== MIME-Version: 1.0 X-Received: by 10.236.106.10 with SMTP id l10mr4194955yhg.101.1405982097907; Mon, 21 Jul 2014 15:34:57 -0700 (PDT) In-Reply-To: References: Date: Tue, 22 Jul 2014 01:34:57 +0300 Subject: Re: asyncip application hangs From: =?UTF-8?B?WWHFn2FyIEFyYWJhY8Sx?= To: python-list@python.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405982107 news.xs4all.nl 2963 [2001:888:2000:d::a6]:52688 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74962 2014-07-22 1:19 GMT+03:00 Ya=C5=9Far Arabac=C4=B1 : > This program is supposed to give me status codes for web pages that > are found on my sitemap.xml file. But program hangs as Tasks wait for > getting something out of the Queue. I think it has something to do > with how I am using asyncio.Queue, but I couldn't figure out what am I > doing wrong here. Can anyone help me with that? Ok, I figured out what was wrong with my code. Since asyncio.Queue.put() is a coroutine, I should have wrapped those with asyncio.Task in order for them to start executing. Therefore, this works; q =3D asyncio.Queue() loop =3D asyncio.get_event_loop() for i in range(num_coroutines): # start 10 tasks tasks.append(asyncio.Task(print_status_code(q))) for loc in soup.find_all('loc'): asyncio.Task(q.put(loc.string)) for i in range(num_coroutines): # Put poison pil. asyncio.Task(q.put(None)) print("%i items in queue" % q.qsize()) loop.run_until_complete(asyncio.wait(tasks)) --=20 http://ysar.net/