Updating client to allow wait for subprocesses also

This commit is contained in:
Adolfo Gómez García 2021-06-21 16:54:34 +02:00
parent 539e96d264
commit d438fcf298
4 changed files with 19 additions and 9 deletions

View File

@ -10,6 +10,6 @@ Package: udsclient3
Section: admin Section: admin
Priority: optional Priority: optional
Architecture: all Architecture: all
Depends: python3-paramiko (>=2.0.0), python2-certifi, python3-cryptography, python3-pyqt5 (>=5.0), python3 (>=3.6), freerdp2-x11 | freerdp-x11 | freerdp-nightly, desktop-file-utils, ${misc:Depends} Depends: python3-paramiko (>=2.0.0), python2-certifi, python3-cryptography, python3-psutil, python3-pyqt5 (>=5.0), python3 (>=3.6), freerdp2-x11 | freerdp-x11 | freerdp-nightly, desktop-file-utils, ${misc:Depends}
Description: Client connector for Universal Desktop Services (UDS) Broker Description: Client connector for Universal Desktop Services (UDS) Broker
This package provides the required components to allow this machine to connect to services provided by UDS Broker. This package provides the required components to allow this machine to connect to services provided by UDS Broker.

View File

@ -40,6 +40,7 @@ AppDir:
- python3-paramiko - python3-paramiko
- python3-cryptography - python3-cryptography
- python3-certifi - python3-certifi
- python3-psutil
- freerdp2-x11 - freerdp2-x11
- freerdp2-wayland - freerdp2-wayland
- x2goclient - x2goclient

View File

@ -11,7 +11,7 @@ Release: %{release}
Summary: Client for Universal Desktop Services (UDS) Broker Summary: Client for Universal Desktop Services (UDS) Broker
License: BSD3 License: BSD3
Group: Applications/Productivity Group: Applications/Productivity
Requires: python3-paramiko python3-qt5 python3-cryptography python3-certifi Requires: python3-paramiko python3-qt5 python3-cryptography python3-certifi python3-psutil
Vendor: Virtual Cable S.L.U. Vendor: Virtual Cable S.L.U.
URL: http://www.udsenterprise.com URL: http://www.udsenterprise.com
Provides: udsclient Provides: udsclient

View File

@ -40,10 +40,15 @@ import time
import base64 import base64
import typing import typing
try:
import psutil
except ImportError:
psutil = None
from .log import logger from .log import logger
_unlinkFiles: typing.List[str] = [] _unlinkFiles: typing.List[str] = []
_tasksToWait: typing.List[typing.Any] = [] _tasksToWait: typing.List[typing.Tuple[typing.Any, bool]] = []
_execBeforeExit: typing.List[typing.Callable[[], None]] = [] _execBeforeExit: typing.List[typing.Callable[[], None]] = []
sys_fs_enc = sys.getfilesystemencoding() or 'mbcs' sys_fs_enc = sys.getfilesystemencoding() or 'mbcs'
@ -147,17 +152,21 @@ def unlinkFiles() -> None:
pass pass
def addTaskToWait(taks: typing.Any) -> None: def addTaskToWait(taks: typing.Any, includeSubprocess: bool = False) -> None:
_tasksToWait.append(taks) _tasksToWait.append(taks)
def waitForTasks() -> None: def waitForTasks() -> None:
for t in _tasksToWait: for task, waitForSubp in _tasksToWait:
try: try:
if hasattr(t, 'join'): if hasattr(task, 'join'):
t.join() task.join()
elif hasattr(t, 'wait'): elif hasattr(task, 'wait'):
t.wait() task.wait()
# If wait for spanwed process (look for process with task pid) and we can look for them...
if psutil and waitForSubp and hasattr(task, 'pid'):
for i in filter(lambda x: x.ppid() == task.pid, psutil.process_iter(attrs=('ppid',))):
i.wait()
except Exception: except Exception:
pass pass