1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
.. _example section:
Examples
========
Demonstration
-------------
The following example demonstrates most of the streams capabilities:
.. literalinclude:: ../examples/demo.py
Simple computation
------------------
This simple example computes ``11² + 13²`` in 1.5 second:
.. literalinclude:: ../examples/simple.py
Preserve a generator
--------------------
This example shows how to preserve an async generator from being closed
by the iteration context:
.. literalinclude:: ../examples/preserve.py
Norm server
-----------
The next example runs a TCP server that computes the euclidean norm of vectors for its clients.
Run the server:
.. sourcecode:: console
$ python3.6 norm_server.py
Serving on ('127.0.0.1', 8888)
Test using a netcat client:
.. sourcecode:: console
$ nc localhost 8888
--------------------------------------
Compute the Euclidean norm of a vector
--------------------------------------
[...]
Check the logs on the server side, and see how the computation is performed on the fly.
.. literalinclude:: ../examples/norm_server.py
:lines: 17-
Extra operators
---------------
This example shows how extra operators can be created and combined with others:
.. literalinclude:: ../examples/extra.py
|