Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74961
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <yasar11732@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'that?': 0.05; 'none:': 0.07; 'skip:u 30': 0.07; 'subject:application': 0.07; '"__main__":': 0.09; '%s",': 0.09; '__name__': 0.09; 'def': 0.12; 'grasp': 0.16; 'pil.': 0.16; 'recieved': 0.16; 'soup': 0.16; 'true:': 0.16; 'url)': 0.16; 'trying': 0.19; 'examples': 0.20; 'code,': 0.22; 'import': 0.22; 'skip:l 30': 0.24; 'file.': 0.24; 'query': 0.26; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'getting': 0.31; 'anyone': 0.31; 'figure': 0.32; 'supposed': 0.32; 'skip:t 40': 0.33; 'skip:u 20': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'yield': 0.36; 'doing': 0.36; 'wrong': 0.37; 'tasks': 0.38; 'to:addr:python-list': 0.38; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'skip:a 30': 0.61; 'today.': 0.61; 'from:charset:utf-8': 0.61; 'simple': 0.61; 'skip:n 10': 0.64; 'skip:w 30': 0.69; 'this;': 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=ZS6ZZ2GbEhsuiktdxqogstTQzfIfKqUbjBn04UWFmXw=; b=DDg14UVE7P7NlyjZTC9pA/+dX5APD+SRsP4gv6w88tCMdOwi0Hzd/79+OJe18l5l4N hK8FNJMz17ybNIbCe7rvojlof0dI2It757nElqFPPfUGoHkxniGayqyvXxGJbCgB0bgZ O9X5lTsBSEnOAINIstM2GPZkxYrlMIVPmF8hge1uuAp9Jukn9CoMRYkzS/oQV5to+l3j 83gGnWV7u+SnbRdIr/VtbJ2ZZAk/D/b/KeGszd2BpDaBr7ZS792tuLfSF0KtxEZXPow9 6lzxRwNGF6mD6EJbdbw+ts/Wo91rgzUp7ez8jYPSClCUrieu/cAYQqVUV1Z+PN3ry8HN mxOA== |
| MIME-Version | 1.0 |
| X-Received | by 10.236.231.178 with SMTP id l48mr21034230yhq.143.1405981182308; Mon, 21 Jul 2014 15:19:42 -0700 (PDT) |
| Date | Tue, 22 Jul 2014 01:19:42 +0300 |
| Subject | asyncip application hangs |
| From | Yaşar Arabacı <yasar11732@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12156.1405981185.18130.python-list@python.org> (permalink) |
| Lines | 58 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1405981185 news.xs4all.nl 2904 [2001:888:2000:d::a6]:47866 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74961 |
Show key headers only | View raw
I am trying to grasp how asyncio works today. Based on the examples
that I found on the docs, I write a simple program like this;
import asyncio
import urllib.request
import urllib.parse
@asyncio.coroutine
def print_status_code(url_q):
while True:
url = yield from url_q.get()
print('URL recieved from q:', url)
if url is None:
return
url = urllib.parse.urlsplit(url)
reader, writer = yield from asyncio.open_connection(url.hostname, 80)
query = ('GET {url.path} HTTP/1.0\r\n'
'Host: {url.hostname}\r\n'
'\r\n').format(url=url)
writer.write(query.encode('latin-1'))
line = yield from reader.readline()
code = line.decode('latin1').split()[0]
print("(%s) %s", code, url.path)
if __name__ == "__main__":
from bs4 import BeautifulSoup as bs
sitemap = urllib.request.urlopen('http://ysar.net/sitemap.xml').read()
soup = bs(sitemap)
print('soup created')
tasks = []
num_coroutines = 10
q = asyncio.Queue()
for i in range(num_coroutines): # start 10 tasks
tasks.append(asyncio.Task(print_status_code(q)))
for loc in soup.find_all('loc'):
q.put(loc.string)
for i in range(num_coroutines): # Put poison pil.
q.put(None)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
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?
--
http://ysar.net/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
asyncip application hangs Yaşar Arabacı <yasar11732@gmail.com> - 2014-07-22 01:19 +0300
csiph-web