Browse Source

re-add set_sync_mode() (OFF,SYNC,ASYNC)

master
heck 2 weeks ago
parent
commit
e02ee00b0f
3 changed files with 19 additions and 13 deletions
  1. +14
    -8
      src/pEp/__init__.py
  2. +3
    -3
      test/start_sync.py
  3. +2
    -2
      test/sync_handshake.py

+ 14
- 8
src/pEp/__init__.py View File

@ -55,16 +55,22 @@ def shutdown_sync() -> None:
# set_sync_mode(SyncModes.Off)
# def set_sync_mode(mode):
# _pEp._set_sync_mode(mode)
# if mode == SyncModes.Sync:
# Sync.shutdown_sync()
# if mode == SyncModes.Async:
# Sync.start_sync()
# if mode == SyncModes.Off:
# Sync.shutdown_sync()
class SyncModes(Enum):
OFF: int = 0
SYNC: int = 1
ASYNC: int = 2
def set_sync_mode(mode):
if mode == SyncModes.SYNC:
Sync.shutdown_sync()
_pEp._init_session(False)
if mode == SyncModes.ASYNC:
_pEp._init_session(True)
Sync.start_sync()
if mode == SyncModes.OFF:
Sync.shutdown_sync()
def is_sync_active() -> bool:
"""True if sync is active, False otherwise"""


+ 3
- 3
test/start_sync.py View File

@ -23,7 +23,7 @@ pEp.myself(alice)
print(alice.fpr)
while True:
pEp.set_sync_mode(pEp.SyncModes.Async)
pEp.set_sync_mode(pEp.SyncModes.ASYNC)
print("start_sync()")
pEp.start_sync()
print("Running...")
@ -34,7 +34,7 @@ while True:
print("END")
time.sleep(3)
pEp.set_sync_mode(pEp.SyncModes.Sync)
pEp.set_sync_mode(pEp.SyncModes.SYNC)
print("start_sync()")
pEp.start_sync()
print("Running...")
@ -45,7 +45,7 @@ while True:
print("END")
time.sleep(3)
pEp.set_sync_mode(pEp.SyncModes.Off)
pEp.set_sync_mode(pEp.SyncModes.OFF)
print("start_sync()")
pEp.start_sync()
print("Running...")


+ 2
- 2
test/sync_handshake.py View File

@ -192,10 +192,10 @@ def run(name, color=None, imap=False, own_ident=1, leave=False):
if multithreaded:
print("Sync Start multi-threaded")
pEp.set_sync_mode(pEp.SyncModes.Async)
pEp.set_sync_mode(pEp.SyncModes.ASYNC)
else:
print("Sync Start single-threaded")
pEp.set_sync_mode(pEp.SyncModes.Sync);
pEp.set_sync_mode(pEp.SyncModes.SYNC);
try:
if leave:


Loading…
Cancel
Save