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

New python 3 asyncio backend #70

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chaussette/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
pass


try:
from chaussette.backend import _asyncio3k
_backends['asyncio3k'] = _asyncio3k.Server
except ImportError as e:
print(e)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this print statement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace it with pass as above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oks!



PY3 = sys.version_info[0] == 3

if not PY3:
Expand Down
36 changes: 36 additions & 0 deletions chaussette/backend/_asyncio3k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import socket
import asyncio
import aiohttp_wsgi
from chaussette.util import create_socket


class Server(object):
address_family = socket.AF_INET
socket_type = socket.SOCK_STREAM

def __init__(self, listener, application=None, backlog=2048,
socket_type=socket.SOCK_STREAM,
address_family=socket.AF_INET):
self.address_family = address_family
self.socket_type = socket_type
host, port = listener
self.socket = create_socket(host, port, self.address_family,
self.socket_type, backlog=backlog)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.application = application
self.backlog = backlog
self.port = port
self.host = host

# P3k asyncio
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)

def serve_forever(self):
aiohttp_wsgi.serve(self.application,
loop=self.loop,
port=self.port,
host=self.host,
**dict(socket=self.socket,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this **dict() here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not really reason to pass a **dict(). I just re-read the code and It has not sense. I'll change it.

backlog=self.backlog))
print("Serving")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logging, not print statements

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oks!