improve output

This commit is contained in:
Alexey Avramov 2020-03-29 14:21:29 +09:00
parent 51d94db378
commit 7ac4314886

View File

@ -146,10 +146,12 @@ def exe(cmd):
cmd_num = cmd_num_dict['cmd_num'] cmd_num = cmd_num_dict['cmd_num']
th_name = threading.current_thread().getName() th_name = threading.current_thread().getName()
log('Executing the command ({}) in {}: {}'.format( log('Executing Command-{} {} with timeout {}s in {}'.format(
cmd_num, cmd_num,
cmd_list,
exe_timeout,
th_name, th_name,
cmd_list)) ))
t3 = monotonic() t3 = monotonic()
try: try:
with Popen(cmd_list) as proc: with Popen(cmd_list) as proc:
@ -157,13 +159,12 @@ def exe(cmd):
proc.wait(timeout=exe_timeout) proc.wait(timeout=exe_timeout)
exit_status = proc.poll() exit_status = proc.poll()
t4 = monotonic() t4 = monotonic()
log('Command ({}) execution completed in {} sec; exit status' log('Command-{} execution completed in {} sec; exit status'
': {}'.format(cmd_num, round(t4 - t3, 3), exit_status)) ': {}'.format(cmd_num, round(t4 - t3, 3), exit_status))
except TimeoutExpired: except TimeoutExpired:
proc.kill() proc.kill()
t4 = monotonic() t4 = monotonic()
log('TimeoutExpired for the command ({}) in {} sec'.format( log('Timeout expired for Command-{}'.format(cmd_num))
cmd_num, round(t4 - t3, 3)))
except Exception as e: except Exception as e:
log('Exception in {}: {}'.format(th_name, e)) log('Exception in {}: {}'.format(th_name, e))
@ -246,7 +247,6 @@ def re_pid_environ(pid):
try: try:
return user.partition('USER=')[2], display, dbus return user.partition('USER=')[2], display, dbus
except UnboundLocalError: except UnboundLocalError:
log('notify helper: UnboundLocalError')
return None return None
@ -277,23 +277,26 @@ def root_notify_env():
return new_env return new_env
def pop(cmd, username): def pop(cmd):
""" run cmd in subprocess.Popen() """ run cmd in subprocess.Popen()
""" """
cmd_num_dict['cmd_num'] += 1 cmd_num_dict['cmd_num'] += 1
cmd_num = cmd_num_dict['cmd_num'] cmd_num = cmd_num_dict['cmd_num']
log('Execute the Command-{} {} in {}'.format(
cmd_num,
cmd,
threading.current_thread().getName()
))
if swap_total == 0: if swap_total == 0:
wait_time = 10 wait_time = 10
else: else:
wait_time = 30 wait_time = 30
th_name = threading.current_thread().getName()
log('Executing Command-{} {} with timeout {}s in {}'.format(
cmd_num,
cmd,
wait_time,
th_name
))
t3 = monotonic() t3 = monotonic()
try: try:
@ -302,19 +305,20 @@ def pop(cmd, username):
proc.wait(timeout=wait_time) proc.wait(timeout=wait_time)
err = proc.poll() err = proc.poll()
t4 = monotonic() t4 = monotonic()
if debug_gui_notifications:
log('Command-{} execution completed in {} sec; exit status'
': {}'.format(cmd_num, round(t4 - t3, 3), err))
except TimeoutExpired: except TimeoutExpired:
proc.kill() proc.kill()
t4 = monotonic() t4 = monotonic()
if debug_gui_notifications: if debug_gui_notifications:
log('TimeoutExpired: notify user: {}'.format(username)) log('Timeout expired for Command-{}'.format(cmd_num))
except Exception as e:
th_name = threading.current_thread().getName()
log('Exception in {}: {}'.format(th_name, e))
if debug_gui_notifications: except Exception as e:
log('Popen time: {} sec; exit status: {}; cmd: {}'.format( log('Exception in {}: {}'.format(th_name, e))
round(t4 - t3, 3), err, cmd))
def send_notification(title, body): def send_notification(title, body):
@ -322,8 +326,7 @@ def send_notification(title, body):
""" """
if self_uid != 0: if self_uid != 0:
cmd = ['notify-send', '--icon=dialog-warning', title, body] cmd = ['notify-send', '--icon=dialog-warning', title, body]
username = '(UID={})'.format(self_uid) pop(cmd)
pop(cmd, username)
return None return None
t1 = monotonic() t1 = monotonic()
@ -350,7 +353,6 @@ def send_notification(title, body):
t2 = monotonic() t2 = monotonic()
if debug_gui_notifications: if debug_gui_notifications:
log('Found env in {} ms{}'.format(round((t2 - t1) * 1000), cached_env)) log('Found env in {} ms{}'.format(round((t2 - t1) * 1000), cached_env))
log(' Title: {}'.format([title])) log(' Title: {}'.format([title]))
log(' Body: {}'.format([body])) log(' Body: {}'.format([body]))
@ -380,7 +382,7 @@ def send_notification(title, body):
body body
] ]
start_thread(pop, cmd, username) start_thread(pop, cmd)
else: else:
if debug_gui_notifications: if debug_gui_notifications: