Skip to content

Task was destroyed but it is pending #10

@MikhailMS

Description

@MikhailMS

Hello there. Thanks for making an effort and writing this extension to the old-fashioned thread-style Zeroconfig package.

However at the moment, when I'm trying to run an example from the README

import asyncio
import logging

from aiozeroconf import ServiceBrowser, Zeroconf

logging.basicConfig(level = logging.DEBUG)

async def do_close(zc):
    await zc.close()

class MyListener:

    def remove_service(self, zeroconf, type_, name):
        print("Service %s removed" % (name,))

    def add_service(self, zeroconf, type_, name):
        asyncio.ensure_future(self.found_service(zeroconf, type_, name))

    async def found_service(self, zeroconf, type_, name):
        info = await zeroconf.get_service_info(type_, name)
        print("Adding {}".format(info))

loop     = asyncio.get_event_loop()
# loop.set_debug(True)

zeroconf = Zeroconf(loop)
listener = MyListener()
browser  = ServiceBrowser(zeroconf, "_googlecast._tcp.local.", listener) # searching for google chromecast

try:
    loop.run_forever()
except KeyboardInterrupt:
    print("Unregistering...")
    loop.run_until_complete(do_close(zeroconf))
finally:
    loop.close()

and after I close it, it fails with following error trace

ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending coro=<ServiceBrowser.run() running at /user/miniconda2/envs/development/lib/python3.6/site-packages/aiozeroconf/aiozeroconf.py:1231> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x17b468>()]>>

Seems to me that may happen because when you try to cancell the ServiceBrowser.run task here it is not cancelled straightaway - Python docs outlines this behaviour here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions