diff --git a/DiscoverUM3Action.py b/DiscoverUM3Action.py index c33e6aed02..cda6ea386a 100644 --- a/DiscoverUM3Action.py +++ b/DiscoverUM3Action.py @@ -27,8 +27,8 @@ class DiscoverUM3Action(MachineAction): Application.getInstance().engineCreatedSignal.connect(self._createAdditionalComponentsView) - self._min_time_between_restart_discovery = 1 - self._time_since_last_discovery = time.time() - self._min_time_between_restart_discovery + self._last_zeroconf_event_time = time.time() + self._zeroconf_change_grace_period = 0.25 # Time to wait after a zeroconf service change before allowing a zeroconf reset printersChanged = pyqtSignal() @@ -41,19 +41,19 @@ class DiscoverUM3Action(MachineAction): @pyqtSlot() def restartDiscovery(self): - # Ensure that there is a bit of time between refresh attempts. + # Ensure that there is a bit of time after a printer has been discovered. # 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. # It's most likely that the QML engine is still creating delegates, where the python side already deleted or # 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 time.time() - self._last_zeroconf_event_time > self._zeroconf_change_grace_period: if not self._network_plugin: self.startDiscovery() else: self._network_plugin.startDiscovery() - self._time_since_last_discovery = time.time() def _onPrinterDiscoveryChanged(self, *args): + self._last_zeroconf_event_time = time.time() self.printersChanged.emit() @pyqtProperty("QVariantList", notify = printersChanged)