Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProactorEventLoop hangs #376

Closed
oicnysa opened this issue May 23, 2015 · 5 comments
Closed

ProactorEventLoop hangs #376

oicnysa opened this issue May 23, 2015 · 5 comments
Labels

Comments

@oicnysa
Copy link

oicnysa commented May 23, 2015

Hi,
I have simple http file server:

import os.path
from os import listdir
import asyncio
from aiohttp import web
import aiohttp_jinja2
import jinja2


@aiohttp_jinja2.template('template2.html')
@asyncio.coroutine
def get(request):

    root = os.path.abspath(os.path.dirname(__file__))
    files = [file_name for file_name in listdir(os.path.join(root, 'files'))
                        if os.path.isfile(os.path.join(root, 'files', file_name))]
    return {'files': files}

if __name__ == "__main__":


    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('C:/ascopy'))

    app.router.add_route('GET', '/', get)
    app.router.add_static('/files/' , 'C:/ascopy/files')



    loop = asyncio.ProactorEventLoop()
    asyncio.set_event_loop(loop)
    f = loop.create_server(app.make_handler(), '127.0.0.1', 8080)
    srv = loop.run_until_complete(f)
    print(' serving on ', srv.sockets[0].getsockname())
    try:

        loop.run_forever()
    except KeyboardInterrupt:
        pass

Server script and template2.html are situated in C:\ascopy. C:\ascopy\files constains some dummy files. template2.html looks like this:

<!DOCTYPE html>
<html>
<head><title>Aiohttp Test Server</title></head>
</body>
<h3>List of files:</h3>
<ul>
  {% for item in files %}
    <li><a href="/files/{{ item }}">{{ item }}</a></li>
  {% endfor %}
</ul>
</body>
</html>

When I'm starting the server and trying to browse the pages, it is simply like loading all the time and nothing happens.
Wireshark shows that SYN, ACK packets and GET request were sent. After that there is a lots of keep-alives.
While I was debugging with pdb, I discovered and that socket is open and client is connected.
There is no such problems with Select event loop, but after I've switched to Proactor this problem appeared. Maybe some suggestions? Thank you in advance.

@asvetlov
Copy link
Member

I'll get a chance to take a look next week.

@oicnysa
Copy link
Author

oicnysa commented May 23, 2015

Thanks!

@oicnysa
Copy link
Author

oicnysa commented May 24, 2015

Hi Andrew,
I've managed to make server work with Proactor. Added yield from, when creating server instance.
Code:

from os import listdir
import asyncio
from aiohttp import web
import aiohttp_jinja2
import jinja2


@aiohttp_jinja2.template('template2.html')
@asyncio.coroutine
def get(request):

    root = os.path.abspath(os.path.dirname(__file__))
    files = [file_name for file_name in listdir(os.path.join(root, 'files'))
                        if os.path.isfile(os.path.join(root, 'files', file_name))]
    return {'files': files}

@asyncio.coroutine
def init(loop):
    app = web.Application(loop=loop)
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('C:/ascopy'))
    print(loop)
    app.router.add_route('GET', '/', get)
    app.router.add_static('/files/' , 'C:/ascopy/files')

    srv = yield from loop.create_server(app.make_handler(),
                                        '127.0.0.1', 8080)
    print("Server started at http://127.0.0.1:8080")
    return srv

if __name__ == "__main__":


    loop = asyncio.ProactorEventLoop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(init(loop))

    try:

        loop.run_forever()
    except KeyboardInterrupt:
        pass

@asvetlov
Copy link
Member

Cool!

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants