Giter VIP home page Giter VIP logo

asyncio-doc's Introduction

Asyncio documentation

Notes to writers

Tutorials should use Python 3.5 async and await keywords rather than @asyncio.coroutine and yield from.

Ideas

  • Advanced section:

How to install Sphinx

Firstly, you need to install the Sphinx tool using the Linux package manager like apt-get or dnf for example.

But if you want to install it via pip , you can create a virtual environment with the venv module of Python 3 :

python3 -m venv env
source env/bin/activate
pip install -r requirements.txt

Once you have installed Sphinx, you can build the documentation.

How to build the documentation

Install Sphinx using the Linux package manager like apt-get or dnf for example. Then build the documentation using:

make html

See also

License

All of the code examples in this site are licensed under the Creative Commons Zero (CC0) license.

All other content of this site is licensed under the Creative Commons Attribution Share Alike 4.0 (CC-BY-SA) license.

asyncio-doc's People

Contributors

brettcannon avatar hoh avatar ludovic-gasc avatar mariatta avatar mathieui avatar matrixise avatar mentaal avatar methane avatar nizish avatar orsenthil avatar pya avatar shuckc avatar sylvainb avatar vstinner avatar vxgmichel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asyncio-doc's Issues

HTTP Client Example is not working

HTTP client example mentioned in below link is not working - latset readthedocs

Below is the valid example from aiohttp docs

import aiohttp
import asyncio

async def fetch(session, url):
    async with session.get(url) as response:
        return await response.text()

async def main():
    async with aiohttp.ClientSession() as session:
        html = await fetch(session, 'http://python.org')
        print(html)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())`

add example explaining concurrent programming with coroutines

I wonder if the following example should be included into the docs to explain concurrent programming with coroutines.

The code uses generator coroutine syntax and is easy to follow

  • the entry and exit points of coroutines are clearly visible
  • therefore it is possible to explain why the code is concurrent and how it works
  • problem with blocking calls can be described
  • it contains parts, which could be moved to separate function - custom event loop
  • the example is in one file (as opposed to tcp echo example)

After describing the example, it could be folded into async/await version running on asyncio event loop. Benefits of asyncio event loop can be shown, i.e.

  • simplified programming
  • other async coroutines can still run, while a socket is waiting for data

Would that make sense?

import socket
import time

PORT = 10000
N = 5

def sender(name):
    s = socket.socket()
    s.connect(('', PORT))
    name = name.encode()
    while True:
        data = yield 
        s.send(name + b'|' + data.encode())

def receiver(client):
    while True:
        yield
        value = client.recv(40)
        client_id, value = value.decode().split('|')
        msg = 'client {}: {}'.format(client_id, value)
        print(msg)


server = socket.socket()
server.bind(('', PORT))
server.listen()

senders = []
receivers = []
for i in range(N):
    s = sender('number {}'.format(i))
    s.send(None)

    c, _ = server.accept()
    r = receiver(c)
    r.send(None)

    senders.append(s)
    receivers.append(r)

for i in range(10):
    for s in senders:
        s.send('item {:03d}'.format(i))
    for r in receivers:
        r.send(None)
    print()
    time.sleep(1)

No license for example code

I could not find any statement about what license the code examples have. Searching this github repo for the word "license" gave 0 results.

The lack of a license means that the authors reserve all rights by default, and it's illegal to copy or use the code in any way, except as allowed by the law, such as for fair use purposes, parody, etc.

This makes it much harder to use the example code as a starting point for a program, which seems to be the intended use. Since I can't legally copy-paste and modify, I'll instead have to learn from the code and then apply what I've learned in my own code. This might be a good thing for me in the end, because I will learn more and better that way, but it is probably asking too much from the intended users of these docs, and also invites unwitting copyright violations.

So, please include a visible statement about which license the examples are released under, or at least add a file called LICENSE, COPYING or similar to the repo with the license text.

asyncio.rtfd.io isn't updating

The last build was a month ago but there have been changes made to this repository since then. Perhaps something went wrong with the webhook to trigger new builds?

aiohttp examples should use async context manager for session creation

E.g. instead of

with aiohttp.ClientSession() as session:
    ...

Use

async with aiohttp.ClientSession() as session:
    ...

Also please be consistent: either pass loop everywhere (aiohttp.Timeout(5, loop=loop), asyncio.gather(*tasks, loop=loop)) or don't pass it at all.

For first case calling asyncio.set_event_loop(None) at very begin of the program effectively checks that loop is passed to any call where it's required.

Example TCP echo server code does not exit cleanly

The example TCP echo server code does not exit cleanly from KeyboardInterrupt if a client is connected:

$ python3  --version
Python 3.6.3

$pip3 show asyncio
Name: asyncio
Version: 3.4.3

$ python3  echo-server.py
Serving on ('127.0.0.1', 9001)
# Connect a client but don't send anything
^C
Task was destroyed but it is pending!
task: <Task pending coro=<handle_echo() done, defined at echo-server.py:3> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fa8f396c0a8>()]>>

Removing the last line (loop.close()) resolves the issue, although I'm not sure why.

Disable the static directory

sphinx-build -b html -d build/doctrees   . build/html
Running Sphinx v4.0.0
making output directory... done
WARNING: html_static_path entry '_build/html/_static' does not exist

hello clock example

The text describes two coroutines that run concurrently

They run for ten minutes, during which the first coroutine is scheduled to run every second, while the second is scheduled to run every minute.

I interpret this text as if both will run during ten minutes and then stop. What appears to happen though is that the second function, print_every_minute, runs for ten minutes while the first function print_every_second goes on for ever. If this is the expected behavior for this piece of code, I find the text a bit misleading to an async novice like me and it could be clarified.

Best regards,
Olav

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.