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

Device discovery increasing thread count #27

Open
chwiede opened this issue Mar 13, 2018 · 1 comment
Open

Device discovery increasing thread count #27

chwiede opened this issue Mar 13, 2018 · 1 comment

Comments

@chwiede
Copy link

chwiede commented Mar 13, 2018

Hi,

thanks for implementing this library, running great except one little thing.

I'm using the lib on a headless raspberry pi in a long-running process. To detect changes of my soundtouch-devices i'm callnig libsoundtouch.discover_devices frequently (e.g. all 30 minutes). After some while, i'm getting this error:

File "/usr/lib/python2.7/threading.py", line 736, in start 
    _start_new_thread(self.__bootstrap, ())
error: can't start new thread

Testscript

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import threading
import libsoundtouch

for i in range(10):
    print("starting discovery... ", end='')
    libsoundtouch.discover_devices(timeout=1)
    print("active threads are now %s" % threading.active_count())

Output

starting discovery... active threads are now 4
starting discovery... active threads are now 7
starting discovery... active threads are now 10
starting discovery... active threads are now 13
starting discovery... active threads are now 16
starting discovery... active threads are now 19
starting discovery... active threads are now 22
starting discovery... active threads are now 25
starting discovery... active threads are now 28
starting discovery... active threads are now 31

So it looks like every call leaves 3 open threads. I'd looked into the code but i didn't find anything suspicious...

Any ideas?

Thanks in advance!

chwiede added a commit to chwiede/libsoundtouch that referenced this issue Mar 18, 2018
Allow zeroconf as external instance
chwiede added a commit to chwiede/libsoundtouch that referenced this issue Mar 18, 2018
Ensure threads do not increase
Ensure browser.cancel() to be called
@chwiede
Copy link
Author

chwiede commented Mar 18, 2018

Figured out my problem. ServiceBrowser.cancel() should be called in discover_devices.

Additonally i've added zeroconf as parameter. So it's possible to keep control over this instance. Default it's set to None, and it will be created in method as before.

Another approach would be to clean up the created zeroconf-instance, but this needs some time.

Please have a look, if accepted i'll make a pull request.

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

No branches or pull requests

1 participant