How to use async/await in Python 3.5?

Question or problem about Python programming: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import time async def foo(): await time.sleep(1) foo() I couldn’t make this dead simple example to run: RuntimeWarning: coroutine ‘foo’ was never awaited foo() How to solve the problem: Solution 1: Running coroutines requires an event loop. Use the asyncio() library to […]

Continue Reading

Type hints: solve circular dependency

Question or problem about Python programming: The following produces NameError: name ‘Client’ is not defined. How can I solve it? class Server(): def register_client(self, client: Client) pass class Client(): def __init__(self, server: Server): server.register_client(self) How to solve the problem: Solution 1: You can use a forward reference by using a string name for the not-yet-defined […]

Continue Reading