Refreshing zeroconf multiple times no longer causes cura crash

CURA-2393
This commit is contained in:
Jaime van Kessel 2016-09-15 13:32:13 +02:00
parent 34aeb50b6a
commit 96e36c0555

View file

@ -9,6 +9,8 @@ from PyQt5.QtQml import QQmlComponent, QQmlContext
import os.path import os.path
import time
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
@ -25,6 +27,9 @@ class DiscoverUM3Action(MachineAction):
Application.getInstance().engineCreatedSignal.connect(self._createAdditionalComponentsView) Application.getInstance().engineCreatedSignal.connect(self._createAdditionalComponentsView)
self._min_time_between_restart_discovery = 2
self._time_since_last_discovery = time.time() - self._min_time_between_restart_discovery
printersChanged = pyqtSignal() printersChanged = pyqtSignal()
@pyqtSlot() @pyqtSlot()
@ -37,10 +42,17 @@ class DiscoverUM3Action(MachineAction):
@pyqtSlot() @pyqtSlot()
def restartDiscovery(self): def restartDiscovery(self):
if not self._network_plugin: # Ensure that there is a bit of time between refresh attempts.
self.startDiscovery() # This is a work around for an issue with Qt 5.5.1 up to Qt 5.7 which can segfault if we do this too often.
else: # It's most likely that the QML engine is still creating delegates, where the python side already deleted or
self._network_plugin.startDiscovery() # garbage collected the data.
# Whatever the case, waiting a bit ensures that it doesn't crash.
if time.time() - self._time_since_last_discovery > self._min_time_between_restart_discovery:
if not self._network_plugin:
self.startDiscovery()
else:
self._network_plugin.startDiscovery()
self._time_since_last_discovery = time.time()
def _onPrinterDiscoveryChanged(self, *args): def _onPrinterDiscoveryChanged(self, *args):
self.printersChanged.emit() self.printersChanged.emit()