1 | #! /usr/bin/python3 -Es |
---|---|
2 | |
3 | import io |
4 | import os |
5 | import subprocess |
6 | import sys |
7 | import tempfile |
8 | |
9 | sge_root = os.environ.get('SGE_ROOT', '/var/lib/gridengine') |
10 | sge_cell = os.environ.get('SGE_CELL', 'default') |
11 | account_file = 'common/accounting' |
12 | |
13 | logpath = os.path.join(sge_root, sge_cell, account_file) |
14 | |
15 | with open(logpath, 'rb') as logfile: |
16 | logfile.seek(-400 * 45000 * 7, os.SEEK_END) |
17 | # Ignore first line as it may be onlym part of a line |
18 | logfile.readline() |
19 | with tempfile.TemporaryDirectory() as new_sge_root: |
20 | new_logpath = os.path.join(new_sge_root, sge_cell, account_file) |
21 | os.makedirs(os.path.dirname(new_logpath)) |
22 | |
23 | for fname in os.listdir(os.path.dirname(logpath)): |
24 | os.symlink( |
25 | os.path.join(os.path.dirname(logpath), fname), |
26 | os.path.join(os.path.dirname(new_logpath), fname)) |
27 | |
28 | os.remove(new_logpath) |
29 | os.mkfifo(new_logpath) |
30 | |
31 | real_qacct = subprocess.Popen( |
32 | ['/usr/bin/qacct'] + sys.argv[1:], |
33 | env=dict(os.environ, SGE_ROOT=new_sge_root)) |
34 | |
35 | with open(new_logpath, 'wb') as new_logfile: |
36 | while real_qacct.poll() is None: |
37 | data = logfile.read(io.DEFAULT_BUFFER_SIZE) |
38 | if not data: |
39 | break |
40 | new_logfile.write(data) |
41 | |
42 | sys.exit(real_qacct.wait()) |
Paste P6446
One implementation for T182451: qacct wrapper
One implementation for T182451: qacct wrapper
Authored by zhuyifei1999 on Dec 9 2017, 1:49 AM.
Tags
None
Subscribers
None