Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74962
| References | <CAFEUn8YM+wA-Ri=GguzLzoQsXeo-Swk7fZgjW+R6-G7U0oMjFg@mail.gmail.com> |
|---|---|
| Date | 2014-07-22 01:34 +0300 |
| Subject | Re: asyncip application hangs |
| From | Yaşar Arabacı <yasar11732@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12157.1405982107.18130.python-list@python.org> (permalink) |
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/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: asyncip application hangs Yaşar Arabacı <yasar11732@gmail.com> - 2014-07-22 01:34 +0300
csiph-web