Skip to content

Commit

Permalink
Drop user supplied loop (#2531)
Browse files Browse the repository at this point in the history
* Drop user supplied loop

* Fix failed tests

* Drop unused imports

* Fix flake
  • Loading branch information
asvetlov authored Nov 18, 2017
1 parent 69c4621 commit ad8f45f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 106 deletions.
24 changes: 5 additions & 19 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import asyncio
import os
import signal
import socket
import stat
import sys
import warnings
from argparse import ArgumentParser
Expand Down Expand Up @@ -376,15 +374,6 @@ def _make_server_creators(handler, *, loop, ssl_context,
)
uris.append('{}://unix:{}:'.format(scheme, path))

# Clean up prior socket path if stale and not abstract.
# CPython 3.5.3+'s event loop already does this. See
# https://github.com/python/asyncio/issues/425
if path[0] not in (0, '\x00'): # pragma: no branch
try:
if stat.S_ISSOCK(os.stat(path).st_mode):
os.remove(path)
except FileNotFoundError:
pass
for sock in socks:
server_creations.append(
loop.create_server(
Expand All @@ -403,11 +392,9 @@ def _make_server_creators(handler, *, loop, ssl_context,
def run_app(app, *, host=None, port=None, path=None, sock=None,
shutdown_timeout=60.0, ssl_context=None,
print=print, backlog=128, access_log_format=None,
access_log=access_logger, handle_signals=True, loop=None):
access_log=access_logger, handle_signals=True):
"""Run an app locally"""
user_supplied_loop = loop is not None
if loop is None:
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop()

app._set_loop(loop)
app.freeze()
Expand Down Expand Up @@ -455,10 +442,9 @@ def run_app(app, *, host=None, port=None, path=None, sock=None,
loop.run_until_complete(handler.shutdown(shutdown_timeout))
finally:
loop.run_until_complete(app.cleanup())
if not user_supplied_loop:
if hasattr(loop, 'shutdown_asyncgens'):
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()
if hasattr(loop, 'shutdown_asyncgens'):
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()


def main(argv):
Expand Down
11 changes: 1 addition & 10 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,7 @@ Utilities
ssl_context=None, print=print, backlog=128, \
access_log_format=None, \
access_log=aiohttp.log.access_logger, \
handle_signals=True, loop=None)
handle_signals=True)

A utility function for running an application, serving it until
keyboard interrupt and performing a
Expand All @@ -2256,8 +2256,6 @@ Utilities
Perhaps production config will use more sophisticated runner but it
good enough at least at very beginning stage.

The function uses *app.loop* as event loop to run.

The server will listen on any host or Unix domain socket path you supply.
If no hosts or paths are supplied, or only a port is supplied, a TCP server
listening on 0.0.0.0 (all hosts) will be launched.
Expand Down Expand Up @@ -2317,13 +2315,6 @@ Utilities
:param bool handle_signals: override signal TERM handling to gracefully
exit the application.

:param loop: an *event loop* used for running the application
(``None`` by default).

If the loop is not explicitly specified the function
closes it by :meth:`~asyncio.AbstractEventLoop.close` call but
**does nothing** for **non-default** loop.


Constants
---------
Expand Down
Loading

0 comments on commit ad8f45f

Please sign in to comment.