Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74962 > unrolled thread

Re: asyncip application hangs

Started byYaşar Arabacı <yasar11732@gmail.com>
First post2014-07-22 01:34 +0300
Last post2014-07-22 01:34 +0300
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: asyncip application hangs Yaşar Arabacı <yasar11732@gmail.com> - 2014-07-22 01:34 +0300

#74962 — Re: asyncip application hangs

FromYaşar Arabacı <yasar11732@gmail.com>
Date2014-07-22 01:34 +0300
SubjectRe: asyncip application hangs
Message-ID<mailman.12157.1405982107.18130.python-list@python.org>
2014-07-22 1:19 GMT+03:00 Yaşar Arabacı <yasar11732@gmail.com>:
> 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 = asyncio.Queue()
    loop = 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))

-- 
http://ysar.net/

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web