forked from windelbouwman/lognplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_demo.py
More file actions
44 lines (31 loc) · 907 Bytes
/
Copy pathserver_demo.py
File metadata and controls
44 lines (31 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
""" Demo on how to receive data via TCP/IP. """
import threading
from lognplot.qt.qtapi import QtWidgets
from lognplot.qt.widgets import SoftScope
from lognplot.server import run_server
import asyncio
try:
from lognplot.web.rest import serve_db_via_rest
except ImportError:
serve_db_via_rest = None
def main():
app = QtWidgets.QApplication([])
scope = SoftScope()
t1 = threading.Thread(
target=run_server, args=(DataSink(scope.add_samples),), daemon=True
)
t1.start()
if serve_db_via_rest:
t2 = threading.Thread(target=rest, args=(scope.db,), daemon=True)
t2.start()
scope.show()
app.exec()
def rest(db):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
serve_db_via_rest(db)
class DataSink:
def __init__(self, add_samples):
self.add_samples = add_samples
if __name__ == "__main__":
main()