diff --git a/CHANGES/3775.doc b/CHANGES/3775.doc new file mode 100644 index 00000000000..8b3c48693d1 --- /dev/null +++ b/CHANGES/3775.doc @@ -0,0 +1 @@ +use ``if __name__ == '__main__':`` in server examples. diff --git a/README.rst b/README.rst index 785ab5cd5ee..28ea02dec5b 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,8 @@ An example using a simple server: web.get('/echo', wshandle), web.get('/{name}', handle)]) - web.run_app(app) + if __name__ == '__main__': + web.run_app(app) Documentation diff --git a/docs/index.rst b/docs/index.rst index f83f96e894b..aa20a78fe99 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -76,8 +76,9 @@ Client example:: html = await fetch(session, 'http://python.org') print(html) - loop = asyncio.get_event_loop() - loop.run_until_complete(main()) + if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) Server example:: @@ -92,7 +93,8 @@ Server example:: app.add_routes([web.get('/', handle), web.get('/{name}', handle)]) - web.run_app(app) + if __name__ == '__main__': + web.run_app(app) For more information please visit :ref:`aiohttp-client` and