<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><br></div><div>Howdy All,</div><div>I have a situation regarding threading that I'm hoping that you gurus can advise on,...</div><div><br></div><div>I'm doing a UI where I spawn a second, threaded process....the child process</div><div>affects the parent process by altering the parent's behaviour and/or animation timing.</div><div><br></div><div>Using modules "threading" and "functools"..</div><div><br></div><div style="margin-left: 40px;"><font style="color: rgb(0, 0, 255);" size="2"><span style="font-family: arial,helvetica,sans-serif;">from threading import Thread</span></font><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><font style="color: rgb(0, 0, 255);" size="2"><span style="font-family: arial,helvetica,sans-serif;">from functools import wraps</span></font><br></div><br>ProcessA does a
standard .ui load, and presents a "revolving door" type of<br>interface for selection. It is similar (though not identical) to one used at <br><br><div style="margin-left: 40px;"><span style="color: rgb(0, 0, 255);">http://video.pbs.org/</span><br></div><br>ProcessB is spawned thusly:<br><br><div style="margin-left: 40px;"><font style="color: rgb(0, 0, 255);" size="2"><span style="font-family: arial,helvetica,sans-serif;">task1(self)</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">for i in range(0, 10):</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;"> print(".")</span></font><br></div><br>...which calls:<br><br><div style="margin-left: 40px;"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family:
arial,helvetica,sans-serif;">@run_async</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">def task1(form):</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> print("task 1")</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> for i in range(0,
1000):</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> for j in range(1, 2):</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> cmd = ("rect = QtCore.QRect( form.pix_%d.geometry() )" % j)</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0,
0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> exec(cmd)</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> x = rect.x()</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family:
arial,helvetica,sans-serif;"> y = rect.y()</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> w = rect.width()</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> h = rect.height()</span></font></span><br style="font-family:
arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> x = x - 1</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> cmd =
("form.pix_%d.setGeometry(%d,%d,%d,%d)" % (j,x,y,w,h) )</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> exec(cmd)</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> form.update()</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family:
arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> time.sleep(.02)</span></font></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"></span></div><span class="tab"><br>which in turn runs:<br><br></span><div style="margin-left: 40px; color: rgb(0, 0, 255);"><span class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">def run_async(func):</span></font></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> @wraps(func)</span></font></span><br style="font-family:
arial,helvetica,sans-serif;"><span class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> def async_func(*args, **kwargs):</span></font></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> func_hl = Thread(target = func, args = args, kwargs = kwargs)</span></font></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> func_hl.start()</span></font></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"><font size="2"><span style="font-family:
arial,helvetica,sans-serif;"> return func_hl</span></font></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"></span><br style="font-family: arial,helvetica,sans-serif;"><span class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;"> return async_func</span></font></span><br></div><br><br><br><div>"ProcessB" uses these...to basic translate some graphical elements back and forth along the X-axis<br>to give the UI an animated, lively look,....not unlike many CNN logo treatments on TV,etc...<br>They are simple, transparent "planes".<br><br>"ProcessA" translates/revolves it's elements via QTimeLine using a 24-step animation cycle<br>that is offset for each subsequent window element. Code snippets look like this:<br><br> <br></div><div style="margin-left:
40px;"><span class="tab"></span></div><div style="margin-left: 40px;"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">self.tl = QtCore.QTimeLine(1000)</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">self.tl.setFrameRange(0, 30)</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">self.connect(self.tl, QtCore.SIGNAL("frameChanged(int)"), self.FocusFadeOutToBlack )</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family:
arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">ETC</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">ETC</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">self.connect(self.tl, QtCore.SIGNAL("finished"), self.FocusFinishFadeOut )</span></font></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);"
class="tab"></span><br style="font-family: arial,helvetica,sans-serif; color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);" class="tab"><font size="2"><span style="font-family: arial,helvetica,sans-serif;">self.tl.start()</span></font></span><br></div><br>The problem that occurs....is that while ProcessB is translating it's simple graphical elements,<br>the user hits a button that tells ProcessA to "move to the next window". ProcessA must move<br>the window to an exact location,...which it does when ProcessB is *not* running. But when<br>ProcessB *is* running,...the windows in ProcessA fall short of their end location. I'm thinking<br>that the "sleep" command in ProcessB may also be affecting ProcessA's timing, something<br>sure is.<br><br>From what I've read....threading process should work independently of each other,<br>and shouldn't cause any "crosstalk" as it were. Not having ProcessB's animating
graphical<br>elements really takes away a lot of the UI's sparkle. Again,..if I don't spawn ProcessB,<br>ProcessA works right every time.<br><br>Can anybody shed any light, experience, or knowledge regarding this phenomena?<br><br>Thank you very much,<br>Cheers,<br>Jim<br><br><br><br><br><br><br><br><div><br style="font-family: arial,helvetica,sans-serif;"></div><div style="margin-left: 40px;"><span class="tab"></span></div><span class="tab"><br><br><br><br><br><br><br><br><br><br><br><br></span><br><br><br><br><br><div><br></div><div><br></div><br><div><br></div></div></body></html>