mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Put get_all_ips onto a thread. Cache the result when we get it.
This commit is contained in:
parent
57f9e2e335
commit
421e7c82fa
@ -54,6 +54,8 @@ def synchronous(tlockname):
|
|||||||
|
|
||||||
class ConnectionListener (Thread):
|
class ConnectionListener (Thread):
|
||||||
|
|
||||||
|
all_ip_addresses = dict()
|
||||||
|
|
||||||
NOT_SERVICED_COUNT = 6
|
NOT_SERVICED_COUNT = 6
|
||||||
|
|
||||||
def __init__(self, driver):
|
def __init__(self, driver):
|
||||||
@ -61,6 +63,7 @@ class ConnectionListener (Thread):
|
|||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.driver = driver
|
self.driver = driver
|
||||||
self.keep_running = True
|
self.keep_running = True
|
||||||
|
all_ip_addresses = dict()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.keep_running = False
|
self.keep_running = False
|
||||||
@ -78,6 +81,11 @@ class ConnectionListener (Thread):
|
|||||||
if not self.keep_running:
|
if not self.keep_running:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if not self.all_ip_addresses:
|
||||||
|
self.all_ip_addresses = get_all_ips()
|
||||||
|
if self.all_ip_addresses:
|
||||||
|
self.driver._debug("All IP addresses", self.all_ip_addresses)
|
||||||
|
|
||||||
if not self.driver.connection_queue.empty():
|
if not self.driver.connection_queue.empty():
|
||||||
queue_not_serviced_count += 1
|
queue_not_serviced_count += 1
|
||||||
if queue_not_serviced_count >= self.NOT_SERVICED_COUNT:
|
if queue_not_serviced_count >= self.NOT_SERVICED_COUNT:
|
||||||
@ -1287,8 +1295,6 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
self.client_can_stream_metadata = False
|
self.client_can_stream_metadata = False
|
||||||
self.client_wants_uuid_file_names = False
|
self.client_wants_uuid_file_names = False
|
||||||
|
|
||||||
self._debug("All IP addresses", get_all_ips())
|
|
||||||
|
|
||||||
message = None
|
message = None
|
||||||
try:
|
try:
|
||||||
self.listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
@ -182,6 +182,7 @@ class ConnectShareAction(InterfaceAction):
|
|||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.share_conn_menu = ShareConnMenu(self.gui)
|
self.share_conn_menu = ShareConnMenu(self.gui)
|
||||||
|
self.share_conn_menu.aboutToShow.connect(self.set_smartdevice_action_state)
|
||||||
self.share_conn_menu.toggle_server.connect(self.toggle_content_server)
|
self.share_conn_menu.toggle_server.connect(self.toggle_content_server)
|
||||||
self.share_conn_menu.control_smartdevice.connect(self.control_smartdevice)
|
self.share_conn_menu.control_smartdevice.connect(self.control_smartdevice)
|
||||||
self.share_conn_menu.config_email.connect(partial(
|
self.share_conn_menu.config_email.connect(partial(
|
||||||
|
@ -5,13 +5,18 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import socket, time, atexit
|
import socket, time, atexit
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
from calibre.utils.filenames import ascii_text
|
from calibre.utils.filenames import ascii_text
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
|
|
||||||
_server = None
|
_server = None
|
||||||
|
|
||||||
def get_all_ips():
|
_all_ip_addresses = dict()
|
||||||
|
|
||||||
|
class AllIpAddressesGetter (Thread):
|
||||||
|
|
||||||
|
def get_all_ips(self):
|
||||||
''' Return a mapping of interface names to the configuration of the
|
''' Return a mapping of interface names to the configuration of the
|
||||||
interface, which includes the ip address, netmask and broadcast addresses
|
interface, which includes the ip address, netmask and broadcast addresses
|
||||||
'''
|
'''
|
||||||
@ -29,6 +34,18 @@ def get_all_ips():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return dict(all_ips)
|
return dict(all_ips)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
global _all_ip_addresses
|
||||||
|
# print 'sleeping'
|
||||||
|
# time.sleep(10)
|
||||||
|
# print 'slept'
|
||||||
|
_all_ip_addresses = self.get_all_ips()
|
||||||
|
|
||||||
|
AllIpAddressesGetter().start()
|
||||||
|
|
||||||
|
def get_all_ips():
|
||||||
|
return _all_ip_addresses
|
||||||
|
|
||||||
def _get_external_ip():
|
def _get_external_ip():
|
||||||
'Get IP address of interface used to connect to the outside world'
|
'Get IP address of interface used to connect to the outside world'
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user