extmod/uasyncio: Fix start_server and wait_closed race condition.
This fix prevents server.wait_closed() from raising an AttributeError when trying to access server.task. This can happen if it is called immediately after start_server().
This commit is contained in:
parent
525a920ca5
commit
de2e081260
|
@ -112,7 +112,6 @@ class Server:
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
s.bind(ai[-1])
|
s.bind(ai[-1])
|
||||||
s.listen(backlog)
|
s.listen(backlog)
|
||||||
self.task = core.cur_task
|
|
||||||
# Accept incoming connections
|
# Accept incoming connections
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -135,7 +134,7 @@ class Server:
|
||||||
# TODO could use an accept-callback on socket read activity instead of creating a task
|
# TODO could use an accept-callback on socket read activity instead of creating a task
|
||||||
async def start_server(cb, host, port, backlog=5):
|
async def start_server(cb, host, port, backlog=5):
|
||||||
s = Server()
|
s = Server()
|
||||||
core.create_task(s._serve(cb, host, port, backlog))
|
s.task = core.create_task(s._serve(cb, host, port, backlog))
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue