def watchdogctl(ctx, kill=False, verbose=True):
tries = <NUM_LIT> if kill else <NUM_LIT:0><EOL>cmd = '<STR_LIT>'.format(ctx.rituals.docs.watchdog.port)<EOL>pidno = <NUM_LIT:0><EOL>pidinfo = capture(cmd, ignore_failures=True)<EOL>while pidinfo:<EOL><INDENT>pidline = next(filter(None, [re.match(r'<STR_LIT>', x) for x in pidinfo.splitlines()]))<EOL>if not pidline:<EOL><INDENT>raise ValueError("<STR_LIT>".format(pidinfo))<EOL><DEDENT>pidno = int(pidline.group(<NUM_LIT:1>), <NUM_LIT:10>)<EOL>if verbose:<EOL><INDENT>ctx.run("<STR_LIT>".format(pidno), echo=False)<EOL>verbose = False<EOL><DEDENT>tries -= <NUM_LIT:1><EOL>if tries <= <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>os.kill(pidno, <NUM_LIT:0>)<EOL><DEDENT>except OSError as exc:  <EOL><INDENT>if exc.errno == <NUM_LIT:3>:<EOL><INDENT>break<EOL><DEDENT>raise<EOL><DEDENT>else:<EOL><INDENT>notify.info("<STR_LIT>".format(pidno))<EOL>ctx.run("<STR_LIT>".format(pidno), echo=False)<EOL>time.sleep(<NUM_LIT>)<EOL><DEDENT><DEDENT>pid = capture(cmd, ignore_failures=True)<EOL><DEDENT>return pidno<EOL>
Control / check a running Sphinx autobuild process.