aiocoap
aiocoap copied to clipboard
WARNING:root:Observation deleted without explicit cancellation
I'm trying to send observation requests to a server, but before the server can send notifications back I get "WARNING:root:Observation deleted without explicit cancellation" printed on the console. I've searched through the sources but I can't find where this message originates from. I suspect one of my Request objects is being deleted.
Here's the jist of the code if anyone spots anything.
from asyncio.queues import Queue
from aiocoap import Message
from aiocoap import Context
from aiocoap import GET
async def start_server():
protocol = await Context.create_client_context()
get_obs_req = Message(code=GET, uri='coap://localhost/temp', observe=0)
request = protocol.request(get_obs_req)
# some logic
request.observation.register_callback(handle_notification)
await request.response
# launch into websockets server
def main():
asyncio.get_event_loop().create_task(start_server())
asyncio.get_event_loop().run_forever()
if __name__ == '__main__':
main()
I'm not sure off my head and can't do a full check right now, but do you return from start_server? That'd be one way how the request would get deleted.
A quick and dirty way to check would be adding global request
as first line of start_server
-- not to stay there, just to narrow the debugging space as I'd see then whether it's this or something else.
(If that works, my next step is to find why register_callback doesn't keep the request object alive for until the callback is unregistered.)
I ended up using async for response in request.observation
so the ClientObservation
hands around. I just started learning asyncio
today and I suspect my coroutine was finishing execution, destroying the Request
.