<commit_before>from cura.MachineAction import MachineAction

from UM.Application import Application
from UM.PluginRegistry import PluginRegistry
from UM.Logger import Logger

from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QUrl, QObject
from PyQt5.QtQml import QQmlComponent, QQmlContext

import os.path

import time

from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")

class DiscoverUM3Action(MachineAction):
    def __init__(self):
        super().__init__("DiscoverUM3Action", catalog.i18nc("@action","Connect via Network"))
        self._qml_url = "DiscoverUM3Action.qml"

        self._network_plugin = None

        self._context = None
        self._additional_component = None
        self._additional_components_view = None

        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()

    @pyqtSlot()
    def startDiscovery(self):
        if not self._network_plugin:
            self._network_plugin = Application.getInstance().getOutputDeviceManager().getOutputDevicePlugin("JediWifiPrintingPlugin")
            self._network_plugin.addPrinterSignal.connect(self._onPrinterDiscoveryChanged)
            self._network_plugin.removePrinterSignal.connect(self._onPrinterDiscoveryChanged)
            self.printersChanged.emit()

    @pyqtSlot()
    def restartDiscovery(self):
        # Ensure that there is a bit of time between refresh attempts.
        # 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 not self._network_plugin:
                self.startDiscovery()
            else:
                self._network_plugin.startDiscovery()
            self._time_since_last_discovery = time.time()

    def _onPrinterDiscoveryChanged(self, *args):<commit_msg>Increased time to 5 sec<commit_after>from cura.MachineAction import MachineAction

from UM.Application import Application
from UM.PluginRegistry import PluginRegistry
from UM.Logger import Logger

from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QUrl, QObject
from PyQt5.QtQml import QQmlComponent, QQmlContext

import os.path

import time

from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")

class DiscoverUM3Action(MachineAction):
    def __init__(self):
        super().__init__("DiscoverUM3Action", catalog.i18nc("@action","Connect via Network"))
        self._qml_url = "DiscoverUM3Action.qml"

        self._network_plugin = None

        self._context = None
        self._additional_component = None
        self._additional_components_view = None

        Application.getInstance().engineCreatedSignal.connect(self._createAdditionalComponentsView)

        self._min_time_between_restart_discovery = 5
        self._time_since_last_discovery = time.time() - self._min_time_between_restart_discovery

    printersChanged = pyqtSignal()

    @pyqtSlot()
    def startDiscovery(self):
        if not self._network_plugin:
            self._network_plugin = Application.getInstance().getOutputDeviceManager().getOutputDevicePlugin("JediWifiPrintingPlugin")
            self._network_plugin.addPrinterSignal.connect(self._onPrinterDiscoveryChanged)
            self._network_plugin.removePrinterSignal.connect(self._onPrinterDiscoveryChanged)
            self.printersChanged.emit()

    @pyqtSlot()
    def restartDiscovery(self):
        # Ensure that there is a bit of time between refresh attempts.
        # 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 not self._network_plugin:
                self.startDiscovery()
            else:
                self._network_plugin.startDiscovery()
            self._time_since_last_discovery = time.time()

    def _onPrinterDiscoveryChanged(self, *args):
{'fraction_non_alphanumeric': 0.07041648776298841, 'fraction_numerical': 0.008372692142550452, 'mean_word_length': 3.432921027592769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7278558', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1255, 'n_words': 327}