Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assesrtion error hit in zeroconf #641

Closed
soreau opened this issue Jul 2, 2022 · 4 comments
Closed

Assesrtion error hit in zeroconf #641

soreau opened this issue Jul 2, 2022 · 4 comments

Comments

@soreau
Copy link
Contributor

soreau commented Jul 2, 2022

I hit this assertion from my program which causes an infinite rapid connection loop. This is the repeated backtrace:

[name(192.168.1.150):8009] Error communicating with socket, resetting connection
[name(192.168.1.150):8009] Unhandled exception in worker thread, attempting reconnect
Traceback (most recent call last):
  File "/home/scott/.local/lib/python3.8/site-packages/pychromecast/socket_client.py", line 538, in run
    if self.run_once(timeout=POLL_TIME_BLOCKING) == 1:
  File "/home/scott/.local/lib/python3.8/site-packages/pychromecast/socket_client.py", line 561, in run_once
    if not self._check_connection():
  File "/home/scott/.local/lib/python3.8/site-packages/pychromecast/socket_client.py", line 690, in _check_connection
    self.initialize_connection()
  File "/home/scott/.local/lib/python3.8/site-packages/pychromecast/socket_client.py", line 295, in initialize_connection
    host, port, service_info = get_host_from_service(
  File "/home/scott/.local/lib/python3.8/site-packages/pychromecast/dial.py", line 38, in get_host_from_service
    service_info = zconf.get_service_info("_googlecast._tcp.local.", service.data)
  File "/home/scott/.local/lib/python3.8/site-packages/zeroconf/_core.py", line 540, in get_service_info
    if info.request(self, timeout, question_type):
  File "/home/scott/.local/lib/python3.8/site-packages/zeroconf/_services/info.py", line 459, in request
    assert zc.loop is not None and zc.loop.is_running()
AssertionError

This happens when I run catt-qt here, and subsequently power cycle a chromecast, but strangely does not happen when I try to add a connection listener to this example. This patch fixes it. This is with Zeroconf version: 0.38.7

soreau added a commit to soreau/pychromecast that referenced this issue Jul 2, 2022
zeroconf asserts that the loop is running, so if we call this function
without the loop running, it will hit the assert.

Closes home-assistant-libs#641.
soreau added a commit to soreau/pychromecast that referenced this issue Jul 2, 2022
zeroconf asserts that the loop is running, so if we call this function
without the loop running, it will hit the assert.

Closes home-assistant-libs#641.
@balloob
Copy link
Collaborator

balloob commented Jul 2, 2022

This is a bug in catt-qt. You need to have a running loop to resolve a service and it needs to run inside the event loop.

@balloob balloob closed this as completed Jul 2, 2022
@soreau
Copy link
Contributor Author

soreau commented Jul 2, 2022

Thanks for the quick reply. Can you elaborate about how to do this? By event loop, do you mean Qt's event loop or something else? Any pointers to the code would be appreciated.

@soreau
Copy link
Contributor Author

soreau commented Jul 3, 2022

if I use

async def myWork():
    chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[name])
    chromecast = chromecast[0]

loop = asyncio.get_event_loop()
loop.run_until_complete(myWork())

it waits the full timeout of 3 seconds and says index out of range for chromecasts[0].

@soreau
Copy link
Contributor Author

soreau commented Jul 3, 2022

Turns out I just needed to wrap the relevant setup code with these calls to run in the main event loop.

loop = QEventLoop()
# setup code
loop.exec()

Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants