mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Revert "Reinitialise Zeroconf network socket upon refresh/start"
This reverts commit a31a4a1e90
.
This commit is contained in:
parent
a31a4a1e90
commit
8bd3b7ea9b
1 changed files with 8 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
||||
from . import NetworkPrinterOutputDevice
|
||||
|
||||
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo, new_socket
|
||||
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo
|
||||
from UM.Logger import Logger
|
||||
from UM.Signal import Signal, signalemitter
|
||||
from UM.Application import Application
|
||||
|
@ -20,7 +20,7 @@ import json
|
|||
class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._zero_conf = Zeroconf()
|
||||
self._zero_conf = None
|
||||
self._browser = None
|
||||
self._printers = {}
|
||||
|
||||
|
@ -53,18 +53,16 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
self.startDiscovery()
|
||||
|
||||
def startDiscovery(self):
|
||||
self.stop()
|
||||
if self._browser:
|
||||
self._browser.cancel()
|
||||
self._browser = None
|
||||
self._old_printers = [printer_name for printer_name in self._printers]
|
||||
self._printers = {}
|
||||
self.printerListChanged.emit()
|
||||
#After network switching, Zeroconf's network socket is no longer functional.
|
||||
#Zeroconf must reinitialise its socket, but reinitialising Zeroconf causes massive CPU usage.
|
||||
#So we only reinitialise Zeroconf's listening socket.
|
||||
self._zero_conf.engine.del_reader(self._zero_conf._listen_socket)
|
||||
self._zero_conf._listen_socket = new_socket() #Warning: Touching Zeroconf's privates! It has no functionality to reinitialise its own socket.
|
||||
self._zero_conf.engine.add_reader(self._zero_conf.listener, self._zero_conf._listen_socket)
|
||||
# After network switching, one must make a new instance of Zeroconf
|
||||
# On windows, the instance creation is very fast (unnoticable). Other platforms?
|
||||
self._zero_conf = Zeroconf()
|
||||
self._browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.', [self._onServiceChanged])
|
||||
|
||||
# Look for manual instances from preference
|
||||
|
@ -125,7 +123,8 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
|
||||
## Stop looking for devices on network.
|
||||
def stop(self):
|
||||
self._zero_conf.close()
|
||||
if self._zero_conf is not None:
|
||||
self._zero_conf.close()
|
||||
|
||||
def getPrinters(self):
|
||||
return self._printers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue