From e889b3a88cac83c3792e39b34f2cb6e245d14531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Wed, 26 Mar 2014 14:25:24 +0100 Subject: [PATCH] ported from master branch fixed mem leak with adding external qt event processing Conflicts: ekgplotter/ekgplotter/main.py --- ekgplotter/ekgplotter/main.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ekgplotter/ekgplotter/main.py b/ekgplotter/ekgplotter/main.py index 757ee6f..a1143bf 100644 --- a/ekgplotter/ekgplotter/main.py +++ b/ekgplotter/ekgplotter/main.py @@ -68,8 +68,6 @@ except ImportError as e: from chaosc.osc_lib import decode_osc - - class OSCThread(threading.Thread): def __init__(self, args): super(OSCThread, self).__init__() @@ -271,7 +269,7 @@ class EkgPlot(object): def update(self, osc_address, value): - print("update"), osc_address + res = self.ekg_regex.match(osc_address) if res: #print("matched data") @@ -295,7 +293,6 @@ class EkgPlot(object): if res: actor_name = res.group(1) actor_obj = self.actors[actor_name] - #print("matched ctl", value, actor_name, actor_obj.active) if value == 1 and not actor_obj.active: #print("actor on", actor_name, actor_obj, self.active_actors) actor_obj.active = True @@ -303,16 +300,14 @@ class EkgPlot(object): self.plot.addItem(actor_obj.plotItem) self.plot.addItem(actor_obj.plotPoint) self.active_actors.append(actor_obj) - assert actor_obj in self.active_actors elif value == 0 and actor_obj.active: - #print("actor off", actor_name, actor_obj, self.active_actors) + #print "actor off", actor_name actor_obj.active = False self.plot.removeItem(actor_obj.plotItem) self.plot.removeItem(actor_obj.plotPoint) try: self.active_actors.remove(actor_obj) except ValueError as e: - #print("ctl", e) pass assert actor_obj not in self.active_actors @@ -346,14 +341,18 @@ class MyHandler(BaseHTTPRequestHandler): actor_names = [b"bjoern", b"merle", b"uwe"] num_data = 100 colors = ["r", "g", "b"] - self.plotter = plotter = EkgPlot(actor_names, num_data, colors) + qtapp = QtGui.QApplication([]) + self.plotter = plotter = EkgPlot(actor_names, num_data, colors) self.send_header("Content-Type", "multipart/x-mixed-replace; boundary=--aaboundary\r\n\r\n") self.end_headers() #lastTime = time.time() #fps = None + event_loop = QtCore.QEventLoop() while 1: + event_loop.processEvents() + qtapp.sendPostedEvents(None, 0) while 1: try: osc_address, args = msg_queue.get_nowait() @@ -440,8 +439,6 @@ def main(): add_subscriber_group(arg_parser, "ekgplotter") args = finalize_arg_parser(arg_parser) - qtapp = QtGui.QApplication([]) - http_host, http_port = resolve_host(args.http_host, args.http_port, args.address_family) server = JustAHTTPServer((http_host, http_port), MyHandler)