multithreading - Object vs Thread object Python -


i coding gui in python , pyqt , parts of logic needs executed in specific time intervals measured in ms. think running parts threads , keep track of time best please correct me if wrong.

second question, can use threads classic objects , use them in same way? call methods or use them specific task , keep them simple possible? because thread nature tempted write run() method procedure , somehow lacking oop approach.

thanks

1st part:

if timed part of code rather computation heavy in qthread - if not there no need make things complicated.

as said x3al in comment, there no obvious reason why should not able timing using qtimer. if need repeating signal can use setinterval. if single signal after x ms can use singleshot (pyqt4-doc).

2nd part:

if part correctly asking advice on how use threads - depends on implementation (movetothread vs subclassing), have @ answers background thread qthread in pyqt

allow me recycle example used before on matter:

class threadobject(qobject): started = pyqtsignal() finished = pyqtsignal()  def __init__(self, var1, var2):     super(threadobject, self).__init__()     self.var1 = var1     self.var2 = var2      self._isrunning = true  def stop(self):     _isrunning = false  def run(self):     # var's , send results needed while _isrunning true  class uielement(qwidget):     # initialize, create ui , on     def clicksomebutton(self):         self.obj = threadobject(self.var1, self.var2) # handle copies of vars object         self.thread = = qthread(self, objectname='workerthread')         self.obj.movetothread(self.thread)         # connect start, stop, run, etc.         self.thread.start() 

hope helps you!


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -