From b15a0d74155e1cd2074acc2aca9504763cd17f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugenio=20Parodi=20=F0=9F=8C=B6=EF=B8=8F?= Date: Thu, 23 Jan 2025 12:15:15 +0000 Subject: [PATCH] Refined the async test --- tests/t.ui/test.ui.034.async.01.py | 41 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tests/t.ui/test.ui.034.async.01.py b/tests/t.ui/test.ui.034.async.01.py index 8f0633ea..d89f7b8c 100755 --- a/tests/t.ui/test.ui.034.async.01.py +++ b/tests/t.ui/test.ui.034.async.01.py @@ -26,6 +26,7 @@ import asyncio import inspect import sys, os import time +from datetime import datetime sys.path.append(os.path.join(sys.path[0],'../..')) import TermTk as ttk @@ -46,36 +47,44 @@ qb.clicked.connect(ttk.TTkHelper.quit) rgl.addWidget(ttk.TTkLogViewer(), 3, 0, 1, 3) +# normal slot with a bolocking call @ttk.pyTTkSlot() def call0(): - res.setText("0 Calling...") - ttk.TTkLog.info("0 Calling...") + now = datetime.now().strftime("[%Y-%m-%d]-[%H:%M:%S]") + res.setText(f"{now} 0 Calling...") + ttk.TTkLog.info(f"{now} 0 Calling...") time.sleep(1) - res.setText("0 Calling... - DONE") - ttk.TTkLog.info("0 Calling... - DONE") + res.setText(f"{now} 0 Calling... - DONE") + ttk.TTkLog.info(f"{now} 0 Calling... - DONE") +# async call wothout slot decorator async def call1(): - res.setText("1 Calling...") - ttk.TTkLog.info("1 Calling...") + now = datetime.now().strftime("[%Y-%m-%d]-[%H:%M:%S]") + res.setText(f"{now} 1 Calling...") + ttk.TTkLog.info(f"{now} 1 Calling...") await asyncio.sleep(3) - res.setText("1 Calling... - DONE") - ttk.TTkLog.info("1 Calling... - DONE") + res.setText(f"{now} 1 Calling... - DONE") + ttk.TTkLog.info(f"{now} 1 Calling... - DONE") +# async call with slot decorator @ttk.pyTTkSlot() async def call2(): - res.setText("2 Calling...") - ttk.TTkLog.info("2 Calling...") + now = datetime.now().strftime("[%Y-%m-%d]-[%H:%M:%S]") + res.setText(f"{now} 2 Calling...") + ttk.TTkLog.info(f"{now} 2 Calling...") await asyncio.sleep(4) - res.setText("2 Calling... - DONE") - ttk.TTkLog.info("2 Calling... - DONE") + res.setText(f"{now} 2 Calling... - DONE") + ttk.TTkLog.info(f"{now} 2 Calling... - DONE") +# async call with slot decorator and arguments @ttk.pyTTkSlot(bool) async def call3(val): - res.setText(f"3 Calling... {val}") - ttk.TTkLog.info(f"3 Calling... {val}") + now = datetime.now().strftime("[%Y-%m-%d]-[%H:%M:%S]") + res.setText(f"{now} 3 Calling... {val}") + ttk.TTkLog.info(f"{now} 3 Calling... {val}") await asyncio.sleep(5) - res.setText(f"3 Calling... {val} - DONE") - ttk.TTkLog.info(f"3 Calling... {val} - DONE") + res.setText(f"{now} 3 Calling... {val} - DONE") + ttk.TTkLog.info(f"{now} 3 Calling... {val} - DONE") print(inspect.iscoroutinefunction(call0)) print(inspect.iscoroutinefunction(call1))