summaryrefslogtreecommitdiffstats
path: root/docs/pages/advanced_topics/asyncio.rst
blob: a692630fdd7f80907c5b24065661c0fd68b0354a (plain)
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
.. _asyncio:

Running on top of the `asyncio` event loop
==========================================

.. note::

    New in prompt_toolkit 3.0. (In prompt_toolkit 2.0 this was possible using a
    work-around).

Prompt_toolkit 3.0 uses asyncio natively. Calling ``Application.run()`` will
automatically run the asyncio event loop.

If however you want to run a prompt_toolkit ``Application`` within an asyncio
environment, you have to call the ``run_async`` method, like this:

.. code:: python

    from prompt_toolkit.application import Application

    async def main():
        # Define application.
        application = Application(
            ...
        )

        result = await application.run_async()
        print(result)

    asyncio.get_event_loop().run_until_complete(main())