Skip to content

asyncio integration: can't assign to variable when awaiting #447

@Tinche

Description

@Tinche

Attaching a very simple reproducer:

import asyncio

from ptpython.repl import embed

loop = asyncio.get_event_loop()


async def test():
    return 1


async def interactive_shell():
    """
    Coroutine that starts a Python REPL from which we can access the global
    counter variable.
    """
    print(
        'You should be able to read and update the "counter[0]" variable from this shell.'
    )
    try:
        await embed(globals=globals(), return_asyncio_coroutine=True, patch_stdout=True)
    except EOFError:
        # Stop the loop when quitting the repl. (Ctrl-D press.)
        loop.stop()


def main():
    asyncio.ensure_future(interactive_shell())

    loop.run_forever()
    loop.close()


if __name__ == "__main__":
    main()

Then, run this and:

>>> a = await test()
/Users/tintvrtkovic/pg/ptpython/.venv/lib/python3.9/site-packages/ptpython/repl.py:268: RuntimeWarning: coroutine '<module>' was never awaited
  exec(code, self.get_globals(), self.get_locals())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions