Skip to content

Commit

Permalink
bioconda_utils\utils.py too-many-branches
Browse files Browse the repository at this point in the history
 The function  run had 13 branches and, while Pylint recommends having no more than 12.  I extracted _handle_process to reduce the complexity.
  • Loading branch information
evidencebp committed Dec 1, 2024
1 parent bc08e5b commit 71ca27e
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions bioconda_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,22 +670,7 @@ def handle_output(output_lines):
else:
masked_cmds = [do_mask(c) for c in cmds]

if proc.poll() is None:
mylogger.log(loglevel, 'Command closed STDOUT/STDERR but is still running')
waitfor = 30
waittimes = 5
for attempt in range(waittimes):
mylogger.log(loglevel, "Waiting %s seconds (%i/%i)", waitfor, attempt+1, waittimes)
try:
proc.wait(timeout=waitfor)
break;
except sp.TimeoutExpired:
pass
else:
mylogger.log(loglevel, "Terminating process")
proc.kill()
proc.wait()
returncode = proc.poll()
returncode = _handle_process(mylogger, loglevel, proc)

if returncode:
if not quiet_failure:
Expand All @@ -697,6 +682,25 @@ def handle_output(output_lines):

return sp.CompletedProcess(masked_cmds, returncode, stdout=output)

def _handle_process(mylogger, loglevel, proc):
if proc.poll() is None:
mylogger.log(loglevel, 'Command closed STDOUT/STDERR but is still running')
waitfor = 30
waittimes = 5
for attempt in range(waittimes):
mylogger.log(loglevel, "Waiting %s seconds (%i/%i)", waitfor, attempt+1, waittimes)
try:
proc.wait(timeout=waitfor)
break;
except sp.TimeoutExpired:
pass
else:
mylogger.log(loglevel, "Terminating process")
proc.kill()
proc.wait()
returncode = proc.poll()
return returncode


def envstr(env):
env = dict(env)
Expand Down

0 comments on commit 71ca27e

Please sign in to comment.