From c090b0bc76f073b22b6bf47653ec8f52fc3382c2 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 4 Dec 2018 13:27:42 +0100 Subject: [PATCH] tests: fix python example --- CMakeLists.txt | 1 + clients/CMakeLists.txt | 1 - clients/python | 1 - .../client => clients/python}/client.py | 31 +++++++++++-------- python/{villas/client => }/CMakeLists.txt | 0 python/villas/client/__init__.py | 0 tests/integration/pipe-python-protobuf.sh | 6 ++-- 7 files changed, 23 insertions(+), 17 deletions(-) delete mode 120000 clients/python rename {python/villas/client => clients/python}/client.py (74%) rename python/{villas/client => }/CMakeLists.txt (100%) delete mode 100644 python/villas/client/__init__.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 80f9b22ad..248feac70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,7 @@ add_subdirectory(etc) add_subdirectory(lib) add_subdirectory(web) add_subdirectory(packaging) +add_subdirectory(python) if(WITH_SRC) add_subdirectory(src) diff --git a/clients/CMakeLists.txt b/clients/CMakeLists.txt index fff7608a6..837540a5c 100644 --- a/clients/CMakeLists.txt +++ b/clients/CMakeLists.txt @@ -20,6 +20,5 @@ # along with this program. If not, see . ################################################################################### -add_subdirectory(python) add_subdirectory(opal) add_subdirectory(shmem) diff --git a/clients/python b/clients/python deleted file mode 120000 index b2616ca4b..000000000 --- a/clients/python +++ /dev/null @@ -1 +0,0 @@ -../python/villas/client/ \ No newline at end of file diff --git a/python/villas/client/client.py b/clients/python/client.py similarity index 74% rename from python/villas/client/client.py rename to clients/python/client.py index 73b22512f..d70b4e0fb 100644 --- a/python/villas/client/client.py +++ b/clients/python/client.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import villas_pb2 -import time, socket, errno, sys, os, os.path +import time, socket, errno, sys, os, signal layer = sys.argv[1] if len(sys.argv) == 2 else 'udp' @@ -44,20 +44,25 @@ print('Ready. Ctrl-C to quit.') msg = villas_pb2.Message() -while True: - try: - dgram = skt.recv(1024) - if not dgram: - break - else: - msg.ParseFromString(dgram) - print(msg) - - skt.send(msg.SerializeToString()) - except KeyboardInterrupt: - print('Shutting down.') +# Gracefully shutdown +def sighandler(signum, frame): + running = False + +signal.signal(signal.SIGINT, sighandler) +signal.signal(signal.SIGTERM, sighandler) + +running = True + +while running: + dgram = skt.recv(1024) + if not dgram: break + else: + msg.ParseFromString(dgram) + print(msg) + + skt.send(msg.SerializeToString()) skt.close() diff --git a/python/villas/client/CMakeLists.txt b/python/CMakeLists.txt similarity index 100% rename from python/villas/client/CMakeLists.txt rename to python/CMakeLists.txt diff --git a/python/villas/client/__init__.py b/python/villas/client/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/integration/pipe-python-protobuf.sh b/tests/integration/pipe-python-protobuf.sh index 936f97d3f..430f6d61b 100755 --- a/tests/integration/pipe-python-protobuf.sh +++ b/tests/integration/pipe-python-protobuf.sh @@ -71,10 +71,10 @@ cat > ${CONFIG_FILE} << EOF } EOF -export PYTHONPATH=${BUILDDIR}/clients/python +export PYTHONPATH=${BUILDDIR}/python:${SRCDIR}/python # Start Python client in background -python ${SRCDIR}/clients/python/villas.py unix & +python ${SRCDIR}/clients/python/client.py unix & CPID=$! # Wait for client to be ready @@ -83,11 +83,13 @@ if [ "${LAYER}" = "unix" ]; then sleep 1 done fi + sleep 1 villas-pipe -l ${NUM_SAMPLES} ${CONFIG_FILE} py-client > ${OUTPUT_FILE} < ${INPUT_FILE} kill ${CPID} +wait ${CPID} # Compare data villas-test-cmp ${CMPFLAGS} ${INPUT_FILE} ${OUTPUT_FILE}