asyncip application hangs

Yaşar Arabacı yasar11732 at
Tue Jul 22 00:19:42 CEST 2014

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

def print_status_code(url_q):
    while True:
        url = yield from url_q.get()
        print('URL recieved from q:', url)
        if url is None:

        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'

        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('').read()
    soup = bs(sitemap)
    print('soup created')
    tasks = []

    num_coroutines = 10

    q = asyncio.Queue()

    for i in range(num_coroutines):  # start 10 tasks

    for loc in soup.find_all('loc'):

    for i in range(num_coroutines):  # Put poison pil.

    loop = asyncio.get_event_loop()

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?

More information about the Python-list mailing list