Skip to content

Commit

Permalink
fix for sr process management on windows, which runs 2 processes per
Browse files Browse the repository at this point in the history
instance... one of which can be ignored.
  • Loading branch information
petersilva committed Apr 17, 2021
1 parent 2dd8156 commit b2188c3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions sarra/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,28 @@ def save_procs(self,File="procs.json"):
f.write(pj +'\n')

def _filter_sr_proc(self,p):

if self.me != p['username'] :
return

# process name 'python3' is not helpful, so overwrite...
if 'python' in p['name']:
if len(p['cmdline']) < 2:
return
n = os.path.basename(p['cmdline'][1])
p['name'] = n

if p['name'].startswith('sr_') and (self.me == p['username']):
if p['name'][0:2] != 'sr':
return

if ( sys.platform == 'win32') and ( p['name'][-4:].lower() == '.exe' ):
# on windows, it seems to fork .exe and then there is a -script.py which is the right pid
# .e.g sr_subscribe.exe -> sr_subscribe-script.py ... If you kill the -script, the .exe goes away.
return

#print( 'pname=%s, self.me=%s, pid=%s, cmdline=%s ' % \
# ( p['name'], p['username'], p['pid'], p['cmdline'] ) )
if p['name'].startswith('sr_'):
self.procs[p['pid']] = p

if p['name'][3:8] == 'audit':
Expand All @@ -156,7 +170,7 @@ def read_proc_file(self,File="procs.json"):
with open(File,'r') as f:
self.me = f.readline().rstrip()
for pj in f.readlines():
p = json.loads(pj)
p = json.loads(pj)
self._filter_sr_proc(p)
pcount += 1
if pcount % 100 == 0 : print( '.', end='', flush=True )
Expand Down

0 comments on commit b2188c3

Please sign in to comment.