CURA-1923: Slicinfo: Using UM.Job instead

As suggested by @awhiemstra handling our "thread" here should be done
with UM.Job.
This commit is contained in:
Thomas Karl Pietrowski 2016-07-26 18:56:57 +02:00
parent 7ab0332a6d
commit 260b682864

View file

@ -11,8 +11,9 @@ from UM.i18n import i18nCatalog
from UM.Logger import Logger from UM.Logger import Logger
from UM.Platform import Platform from UM.Platform import Platform
from UM.Qt.Duration import DurationFormat from UM.Qt.Duration import DurationFormat
from UM.Job import Job
from threading import Thread import time
import platform import platform
import math import math
import urllib.request import urllib.request
@ -21,12 +22,12 @@ import ssl
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
class SliceInfoThread(Thread): class SliceInfoThread(Job):
data = None data = None
url = None url = None
def __init__(self, url, data): def __init__(self, url, data):
Thread.__init__(self) Job.__init__(self)
self.url = url self.url = url
self.data = data self.data = data
@ -68,17 +69,17 @@ class SliceInfo(Extension):
self.send_slice_info_message.actionTriggered.connect(self.messageActionTriggered) self.send_slice_info_message.actionTriggered.connect(self.messageActionTriggered)
self.send_slice_info_message.show() self.send_slice_info_message.show()
self.runningThreads = [] self.runningJobs = []
def __del__(self): def __del__(self):
for thread in self.threadedReports: for job in self.runningJobs:
if thread.is_alive(): while not job.isFinished():
thread.join() # Wait for threads - shouldn't take much more time than the timeout. See above.. time.sleep(1) # Wait for threads - shouldn't take much more time than the timeout. See above..
def _removeFinishedThreads(self): def _removeFinishedThreads(self):
for process in self.runningThreads: for job in self.runningJobs:
if not process.is_alive(): if job.isFinished():
self.runningThreads.remove(process) # Remove finished threads self.runningJobs.remove(job) # Remove finished threads
def messageActionTriggered(self, message_id, action_id): def messageActionTriggered(self, message_id, action_id):
self.send_slice_info_message.hide() self.send_slice_info_message.hide()
@ -152,9 +153,9 @@ class SliceInfo(Extension):
binary_data = submitted_data.encode("utf-8") binary_data = submitted_data.encode("utf-8")
# Sending slice info non-blocking # Sending slice info non-blocking
reportThread = SliceInfoThread(self.info_url, binary_data) reportJob = SliceInfoThread(self.info_url, binary_data)
self.runningThreads.append(reportThread) self.runningJobs.append(reportJob)
reportThread.start() reportJob.start()
except: except:
# We really can't afford to have a mistake here, as this would break the sending of g-code to a device # We really can't afford to have a mistake here, as this would break the sending of g-code to a device
# (Either saving or directly to a printer). The functionality of the slice data is not *that* important. # (Either saving or directly to a printer). The functionality of the slice data is not *that* important.