diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 285cd14680..b8bf50aba7 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -71,6 +71,8 @@ class ConnectionListener (Thread): def run(self): queue_not_serviced_count = 0 device_socket = None + get_all_ips(reinitialize=True) + while self.keep_running: try: time.sleep(1) diff --git a/src/calibre/utils/mdns.py b/src/calibre/utils/mdns.py index 225cc90748..aebb2b2e09 100644 --- a/src/calibre/utils/mdns.py +++ b/src/calibre/utils/mdns.py @@ -14,7 +14,7 @@ _server = None _all_ip_addresses = dict() -class AllIpAddressesGetter (Thread): +class AllIpAddressesGetter(Thread): def get_all_ips(self): ''' Return a mapping of interface names to the configuration of the @@ -37,13 +37,20 @@ class AllIpAddressesGetter (Thread): def run(self): global _all_ip_addresses # print 'sleeping' -# time.sleep(10) +# time.sleep(15) # print 'slept' _all_ip_addresses = self.get_all_ips() -AllIpAddressesGetter().start() +_ip_address_getter_thread = None -def get_all_ips(): +def get_all_ips(reinitialize=False): + global _all_ip_addresses, _ip_address_getter_thread + if not _ip_address_getter_thread or (reinitialize and not + _ip_address_getter_thread.is_alive()): + _all_ip_addresses = dict() + _ip_address_getter_thread = AllIpAddressesGetter() + _ip_address_getter_thread.setDaemon(True) + _ip_address_getter_thread.start() return _all_ip_addresses def _get_external_ip():