changed ekgplotter osc thread to a process
This commit is contained in:
parent
e889b3a88c
commit
e865fe53d2
|
@ -31,8 +31,7 @@
|
||||||
#gc.set_debug(gc.DEBUG_LEAK)
|
#gc.set_debug(gc.DEBUG_LEAK)
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import threading
|
from queue import Empty
|
||||||
import queue
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import string,cgi,time, random, socket
|
import string,cgi,time, random, socket
|
||||||
from os import curdir, sep
|
from os import curdir, sep
|
||||||
|
@ -55,6 +54,8 @@ from pyqtgraph.widgets.PlotWidget import PlotWidget
|
||||||
from chaosc.argparser_groups import *
|
from chaosc.argparser_groups import *
|
||||||
from chaosc.lib import resolve_host
|
from chaosc.lib import resolve_host
|
||||||
|
|
||||||
|
from multiprocessing import Process, Queue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from chaosc.c_osc_lib import *
|
from chaosc.c_osc_lib import *
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -68,9 +69,10 @@ except ImportError as e:
|
||||||
from chaosc.osc_lib import decode_osc
|
from chaosc.osc_lib import decode_osc
|
||||||
|
|
||||||
|
|
||||||
class OSCThread(threading.Thread):
|
class OSCThread(Process):
|
||||||
def __init__(self, args):
|
def __init__(self, args, queue):
|
||||||
super(OSCThread, self).__init__()
|
super(OSCThread, self).__init__()
|
||||||
|
self.msg_queue = queue
|
||||||
self.args = args
|
self.args = args
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
|
@ -127,20 +129,20 @@ class OSCThread(threading.Thread):
|
||||||
if reads:
|
if reads:
|
||||||
osc_input = reads[0].recv(128)
|
osc_input = reads[0].recv(128)
|
||||||
osc_address, typetags, messages = decode_osc(osc_input, 0, len(osc_input))
|
osc_address, typetags, messages = decode_osc(osc_input, 0, len(osc_input))
|
||||||
#print("thread osc_address", osc_address)
|
print("thread: osc_address", osc_address)
|
||||||
if osc_address.find(b"ekg") > -1 or osc_address.find(b"plot") != -1:
|
if osc_address.find(b"ekg") > -1 or osc_address.find(b"plot") != -1:
|
||||||
#print("send", osc_address)
|
#print("send", osc_address)
|
||||||
msg_queue.put_nowait((osc_address, messages))
|
self.msg_queue.put_nowait((osc_address, messages))
|
||||||
else:
|
else:
|
||||||
msg_queue.put_nowait((b"/bjoern/ekg", [0]))
|
print("thread: dummy values")
|
||||||
msg_queue.put_nowait((b"/merle/ekg", [0]))
|
self.msg_queue.put_nowait((b"/bjoern/ekg", [0]))
|
||||||
msg_queue.put_nowait((b"/uwe/ekg", [0]))
|
self.msg_queue.put_nowait((b"/merle/ekg", [0]))
|
||||||
|
self.msg_queue.put_nowait((b"/uwe/ekg", [0]))
|
||||||
|
time.sleep(0.01)
|
||||||
self.unsubscribe_me()
|
self.unsubscribe_me()
|
||||||
print("OSCThread is going down")
|
print("OSCThread is going down")
|
||||||
|
|
||||||
|
|
||||||
msg_queue = queue.Queue()
|
|
||||||
|
|
||||||
class Actor(object):
|
class Actor(object):
|
||||||
shadowPen = pg.mkPen(255, 255, 255)
|
shadowPen = pg.mkPen(255, 255, 255)
|
||||||
brush = pg.mkBrush("w")
|
brush = pg.mkBrush("w")
|
||||||
|
@ -333,8 +335,8 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(data)
|
self.wfile.write(data)
|
||||||
elif self.path.endswith(".mjpeg"):
|
elif self.path.endswith(".mjpeg"):
|
||||||
self.thread = thread = OSCThread(self.server.args)
|
msg_queue = Queue()
|
||||||
thread.daemon = True
|
self.thread = thread = OSCThread(self.server.args, msg_queue)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
@ -356,9 +358,10 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
osc_address, args = msg_queue.get_nowait()
|
osc_address, args = msg_queue.get_nowait()
|
||||||
except queue.Empty:
|
except Empty as e:
|
||||||
|
print("queue error", e, type(e))
|
||||||
break
|
break
|
||||||
|
print("main: got value", osc_address, args)
|
||||||
plotter.update(osc_address, args[0])
|
plotter.update(osc_address, args[0])
|
||||||
|
|
||||||
exporter = pg.exporters.ImageExporter.ImageExporter(plotter.plot.plotItem)
|
exporter = pg.exporters.ImageExporter.ImageExporter(plotter.plot.plotItem)
|
||||||
|
|
Loading…
Reference in New Issue