mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
another iteration
This commit is contained in:
@@ -6,15 +6,17 @@ from deltachat.capi import lib
|
|||||||
from deltachat.account import EventLogger
|
from deltachat.account import EventLogger
|
||||||
|
|
||||||
|
|
||||||
def make_event_thread(dc_context, start):
|
class EventThread(threading.Thread):
|
||||||
def run():
|
def __init__(self, dc_context):
|
||||||
lib.dc_context_run(dc_context, lib.py_dc_callback)
|
self.dc_context = dc_context
|
||||||
|
super(EventThread, self).__init__()
|
||||||
|
self.setDaemon(1)
|
||||||
|
|
||||||
thread = threading.Thread(target=run)
|
def run(self):
|
||||||
thread.setDaemon(1)
|
lib.dc_context_run(self.dc_context, lib.py_dc_callback)
|
||||||
if start:
|
|
||||||
thread.start()
|
def stop(self):
|
||||||
return thread
|
lib.dc_context_shutdown(self.dc_context)
|
||||||
|
|
||||||
|
|
||||||
def test_empty_context():
|
def test_empty_context():
|
||||||
@@ -32,14 +34,10 @@ def test_start_stop_event_thread_basic():
|
|||||||
print("1")
|
print("1")
|
||||||
ctx = capi.lib.dc_context_new(ffi.NULL, ffi.NULL)
|
ctx = capi.lib.dc_context_new(ffi.NULL, ffi.NULL)
|
||||||
print("2")
|
print("2")
|
||||||
ev_thread = make_event_thread(ctx, start=False)
|
ev_thread = EventThread(ctx)
|
||||||
print("3 -- starting event thread")
|
print("3 -- starting event thread")
|
||||||
ev_thread.start()
|
ev_thread.start()
|
||||||
print("4 -- started thread, closing context")
|
print("4 -- stopping event thread")
|
||||||
capi.lib.dc_close(ctx)
|
|
||||||
print("5 -- clear context callback")
|
|
||||||
clear_context_callback(ctx)
|
|
||||||
print("6 -- stopping event thread")
|
|
||||||
ev_thread.stop()
|
ev_thread.stop()
|
||||||
|
|
||||||
def test_dc_close_events(tmpdir):
|
def test_dc_close_events(tmpdir):
|
||||||
@@ -53,7 +51,8 @@ def test_dc_close_events(tmpdir):
|
|||||||
ctx,
|
ctx,
|
||||||
lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2)
|
lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2)
|
||||||
)
|
)
|
||||||
ev_thread = make_event_thread(ctx, start=True)
|
ev_thread = EventThread(ctx)
|
||||||
|
ev_thread.start()
|
||||||
|
|
||||||
p = tmpdir.join("hello.db")
|
p = tmpdir.join("hello.db")
|
||||||
lib.dc_open(ctx, p.strpath.encode("ascii"), ffi.NULL)
|
lib.dc_open(ctx, p.strpath.encode("ascii"), ffi.NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user