Browse Source

adding shutdown_sync()

PYADPT-55
Volker Birk 6 years ago
parent
commit
61ac5cda5a
  1. 2
      src/adapter.hh
  2. 11
      src/pEpmodule.cc
  3. 8
      test/sync_handshake.py
  4. 1
      test/sync_test.py

2
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);

11
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));

8
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__":

1
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)

Loading…
Cancel
Save