[~] Refactor
This commit is contained in:
parent
4144f877a8
commit
924fe9b796
@ -1,23 +1,22 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import functools
|
|
||||||
import re
|
|
||||||
import tempfile
|
|
||||||
import signal
|
|
||||||
import datetime
|
import datetime
|
||||||
import sys
|
import functools
|
||||||
import select
|
import io
|
||||||
import subprocess
|
import json
|
||||||
import pprint
|
import logging
|
||||||
import socket
|
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import json
|
import pprint
|
||||||
import traceback
|
import re
|
||||||
import time
|
import select
|
||||||
import sys
|
import signal
|
||||||
import io
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
def custom_notify(
|
def custom_notify(
|
||||||
title=None,
|
title=None,
|
||||||
@ -219,7 +218,6 @@ def chrome(
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
def eternal_oom(argv):
|
def eternal_oom(argv):
|
||||||
import signal
|
import signal
|
||||||
import re
|
import re
|
||||||
@ -240,6 +238,18 @@ def eternal_oom(argv):
|
|||||||
default=None,
|
default=None,
|
||||||
type=int,
|
type=int,
|
||||||
)
|
)
|
||||||
|
parser.add_option(
|
||||||
|
'--one_shot_clean',
|
||||||
|
dest='one_shot_clean',
|
||||||
|
action='store_true',
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
|
parser.add_option(
|
||||||
|
'--one_shot_app',
|
||||||
|
dest='one_shot_app',
|
||||||
|
default=[],
|
||||||
|
action='append',
|
||||||
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
'--period',
|
'--period',
|
||||||
dest='period',
|
dest='period',
|
||||||
@ -268,6 +278,55 @@ def eternal_oom(argv):
|
|||||||
|
|
||||||
self_pid = os.getpid()
|
self_pid = os.getpid()
|
||||||
|
|
||||||
|
if isinstance(options.one_shot_clean, bool) and options.one_shot_clean:
|
||||||
|
if len(options.one_shot_app) == 0:
|
||||||
|
options.one_shot_app = ['chrome', 'teams']
|
||||||
|
|
||||||
|
config = dict(
|
||||||
|
chrome=(r'chrome.*type=renderer', r'^.*--extension-process.*$'),
|
||||||
|
teams=(r'teams.*type=renderer', None),
|
||||||
|
)
|
||||||
|
|
||||||
|
for app in options.one_shot_app:
|
||||||
|
p = config[app]
|
||||||
|
|
||||||
|
try:
|
||||||
|
t1 = subprocess.check_output([
|
||||||
|
'pgrep', '-a', '-f', p[0]
|
||||||
|
]).decode('utf-8')
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
t2 = t1.splitlines()
|
||||||
|
if not p[1] is None:
|
||||||
|
t3 = [o for o in t2 if re.compile(p[1]).match(o) is None]
|
||||||
|
else:
|
||||||
|
t3 = t2
|
||||||
|
t4 = [
|
||||||
|
int(o.split()[0]) for o in t3
|
||||||
|
]
|
||||||
|
|
||||||
|
for pid in t4:
|
||||||
|
if pid == self_pid:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
os.kill(pid, signal.SIGTERM)
|
||||||
|
|
||||||
|
logging.info(json.dumps(dict(
|
||||||
|
apps=options.one_shot_app,
|
||||||
|
count=len(t4),
|
||||||
|
processes=[
|
||||||
|
o.split()[:3] for o in t3
|
||||||
|
],
|
||||||
|
)))
|
||||||
|
|
||||||
|
if len(t4) > 0:
|
||||||
|
print(
|
||||||
|
'\n'.join([
|
||||||
|
str(o.split()[:3]) for o in t3
|
||||||
|
])
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
if options.period is None:
|
if options.period is None:
|
||||||
options.period = 1
|
options.period = 1
|
||||||
if options.memory_limit is None:
|
if options.memory_limit is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user