From b230dbab3ec51c8ad493c4a06158e40801b07d0a Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Tue, 21 May 2019 17:34:19 +0100 Subject: [PATCH] [3.5] if __name__ == '__main__', fix #3775 (#3788) (cherry picked from commit 506c244d) Co-authored-by: Samuel Colvin --- CHANGES/3775.doc | 1 + README.rst | 3 ++- docs/index.rst | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 CHANGES/3775.doc 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 0bf38b1fee5..6933cf8e4af 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