From 61ac5cda5a81035ab4e68256039fca8cb6b67e63 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Tue, 9 Jul 2019 15:25:27 +0200 Subject: [PATCH] adding shutdown_sync() --- src/adapter.hh | 2 ++ src/pEpmodule.cc | 11 +++++++++++ test/sync_handshake.py | 8 ++++++-- test/sync_test.py | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/adapter.hh b/src/adapter.hh index 8ae71ff..d1e921a 100644 --- a/src/adapter.hh +++ b/src/adapter.hh @@ -32,6 +32,8 @@ namespace pEp { return q; } + void shutdown_sync() { queue().push_front(nullptr); } + protected: static PyObject *ui_object(PyObject *value = nullptr); static int _inject_sync_event(SYNC_EVENT ev, void *management); diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index eb6cb53..d1db2f5 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -108,6 +108,11 @@ namespace pEp { { ::do_sync_protocol(adapter.session(), nullptr); } + + void shutdown_sync() + { + adapter.shutdown_sync(); + } } } @@ -502,6 +507,12 @@ BOOST_PYTHON_MODULE(pEp) "implementation call this function in your sync thread\n" ); + def("shutdown_sync", &pEp::PythonAdapter::shutdown_sync, + "shutdown_sync()\n" + "\n" + "call this from another thread to shut down the sync thread\n" + ); + // codecs call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search)); diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 35d1405..a3a993a 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -121,6 +121,10 @@ class UserInterface(pEp.UserInterface): the_end = True +def shutdown_sync(): + pEp.shutdown_sync() + + def run(name, color=None): global device_name device_name = name @@ -142,7 +146,6 @@ def run(name, color=None): pEp.do_sync_protocol() print(colored("********* ", "yellow") + colored("leaving sync_thread", color)) sync = Thread(target=sync_thread) - sync.daemon = True sync.start() else: sync = None @@ -158,7 +161,8 @@ def run(name, color=None): msg2, keys, rating, flags = msg.decrypt() except KeyboardInterrupt: - pass + shutdown_sync() + sys.exit() if __name__=="__main__": diff --git a/test/sync_test.py b/test/sync_test.py index e4d0dc8..1849305 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -30,6 +30,7 @@ def test_for(path, color=None, end_on=None, mt=False): if end_on: sync_handshake.end_on = end_on sync_handshake.multithreaded = mt + sync_handshake.run(path, color) os.chdir(cwd)