This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker.
commit 7d6c36b9ead1625c347124a1cd7ccd6203e15c29 Author: Mike Gabriel <mike.gabr...@das-netzwerkteam.de> Date: Fri Sep 14 12:28:04 2018 +0200 x2gobroker/agent.py: Move delay_execution() function over to x2gobroker/utils.py. --- x2gobroker/agent.py | 27 +-------------------------- x2gobroker/utils.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/x2gobroker/agent.py b/x2gobroker/agent.py index 3563da2..935c330 100644 --- a/x2gobroker/agent.py +++ b/x2gobroker/agent.py @@ -22,7 +22,6 @@ import os.path import subprocess import paramiko import io -import time import socket import logging @@ -37,34 +36,10 @@ import x2gobroker.defaults import x2gobroker.x2gobroker_exceptions import x2gobroker.utils from x2gobroker.loggers import logger_broker, logger_error +from x2gobroker.utils import delayed_execution tasks = {} - -def delayed_execution(agent_func, delay=0, **kwargs): - - forkpid = os.fork() - if forkpid == 0: - - # close stdin, stdout and stderr in the forked process... - for nm in os.listdir("/proc/self/fd"): - if nm.startswith('.'): - continue - fd = int(nm) - if fd in (0,1,2): - os.close(fd) - - # wait for the given delay period - i = 0 - while i < delay: - time.sleep(1) - i += 1 - - # execute the function requested - agent_func(**kwargs) - os._exit(0) - - def has_remote_broker_agent_setup(): """\ Peform some integrity checks that may indicate that a remote diff --git a/x2gobroker/utils.py b/x2gobroker/utils.py index 8f703db..3e16985 100644 --- a/x2gobroker/utils.py +++ b/x2gobroker/utils.py @@ -35,6 +35,7 @@ import distutils.version import pwd, grp import socket import binascii +import time def _checkConfigFileDefaults(data_structure): """\ @@ -410,3 +411,40 @@ def get_key_fingerprint_with_colons(key): if idx % 2 == 0: _colon_fingerprint += ':' return _colon_fingerprint.rstrip(':') + +def delayed_execution(agent_func, delay, *args, **kwargs): + """\ + Delay execution of a function. + + :param func: function to be executed. + :type func: ``func`` + :param delay: delay of the function start in seconds + :type delay: ``int`` + :param args: arg parameters to be handed over to the + to-be-delayed function + :type args: ``list`` + :param kwargs: kwarg parameters to be handed over to the + to-be-delayed function + :type kwargs: ``dict`` + + """ + forkpid = os.fork() + if forkpid == 0: + + # close stdin, stdout and stderr in the forked process... + for nm in os.listdir("/proc/self/fd"): + if nm.startswith('.'): + continue + fd = int(nm) + if fd in (0,1,2): + os.close(fd) + + # wait for the given delay period + i = 0 + while i < delay: + time.sleep(1) + i += 1 + + # execute the function requested + agent_func(*args, **kwargs) + os._exit(0) -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git _______________________________________________ x2go-commits mailing list x2go-commits@lists.x2go.org https://lists.x2go.org/listinfo/x2go-commits