From 03a886e685fa92ae3eddc9f80c67e98fd49d06b6 Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Sat, 12 Jan 2019 01:23:05 +0900 Subject: [PATCH] update readme --- README.md | 2 +- nohang_notify_low_mem | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ce8acff..394e9f3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Nohang is a highly configurable daemon for Linux which is able to correctly prevent [out of memory](https://en.wikipedia.org/wiki/Out_of_memory) (OOM) and keep system responsiveness in low memory conditions. -![pic](https://i.imgur.com/DmqFxaB.png) +![pic](https://i.imgur.com/ixF1JTt.png) ## What is the problem? diff --git a/nohang_notify_low_mem b/nohang_notify_low_mem index 9917add..72fdfa0 100755 --- a/nohang_notify_low_mem +++ b/nohang_notify_low_mem @@ -14,7 +14,7 @@ from argparse import ArgumentParser from os import listdir from subprocess import Popen, TimeoutExpired -wait_time = 2 +wait_time = 10 parser = ArgumentParser() @@ -145,14 +145,18 @@ if len(b) > 0: dbus_tuple = dbus_env.partition('=') display_key, display_value = display_tuple[0], display_tuple[2] dbus_key, dbus_value = dbus_tuple[0], dbus_tuple[2] - try: - Popen(['sudo', '-u', username, - 'notify-send', '--icon=dialog-warning', - '{}'.format(title), '{}'.format(body) - ], env={ - display_key: display_value, dbus_key: dbus_value - }).wait(wait_time) - except TimeoutExpired: - print('TimeoutExpired: notify ' + username) + + with Popen(['sudo', '-u', username, + 'notify-send', '--icon=dialog-warning', + '{}'.format(title), '{}'.format(body) + ], env={ + display_key: display_value, + dbus_key: dbus_value + }) as proc: + try: + proc.wait(timeout=wait_time) + except TimeoutExpired: + proc.kill() + print('TimeoutExpired: notify' + username) else: print('Low memory warnings: nobody logged in with GUI. Nothing to do.')