Fixed cancelling task, need to figure out how to handle CancelledError properly

This commit is contained in:
nocturn9x 2020-03-20 11:32:53 +01:00
parent 61503a44db
commit d06813cd73
2 changed files with 9 additions and 2 deletions

View File

@ -29,6 +29,12 @@ class Task:
def __repr__(self):
return f"<giambio.core.Task({self.coroutine}, {self.status}, {self.joined})"
async def cancel(self):
return await cancel(self)
async def join(self):
return await join(self)
class EventLoop:

View File

@ -23,7 +23,8 @@ async def make_srv(address: tuple):
while True:
conn, addr = await asock.accept()
logging.info(f"{addr} connected")
loop.spawn(echo_server(conn, addr))
task = loop.spawn(echo_server(conn, addr))
await task.cancel()
async def echo_server(sock: AsyncSocket, addr: tuple):
@ -42,4 +43,4 @@ async def echo_server(sock: AsyncSocket, addr: tuple):
logging.info(f"Connection from {addr} closed")
loop.start(make_srv, ('', 1500))
loop.start(make_srv, ('', 1501))