Skip to content

Commit

Permalink
Make it work when start=false for a program
Browse files Browse the repository at this point in the history
  • Loading branch information
R2Boyo25 committed Feb 9, 2023
1 parent 1b095ad commit f346a8a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions villicus.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,35 @@ def start(self):
self.process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=workdir, env=self.env, shell=True, preexec_fn=os.setsid)

if not self.process:
return

flags = fcntl(self.process.stdout, F_GETFL)
fcntl(self.process.stdout, F_SETFL, flags | O_NONBLOCK)

def kill(self):
if not self.process:
return

os.killpg(self.process.pid, signal.SIGTERM)

@property
def out(self):
if not self.process:
return ""

o = ""
if self.running:
while True:
try:
o += read(self.process.stdout.fileno(), 4096).decode()
except OSError:
break
else:
o += self.process.stdout.read().decode()
else:
o += self.process.stdout.read().decode()

if o.strip().strip("\n") != "":
self.curout.append(o.strip("\n"))
if o.strip().strip("\n") != "":
self.curout.append(o.strip("\n"))

return "\n".join(self.curout)

Expand All @@ -104,11 +113,11 @@ def running(self):

@property
def returncode(self):
try:
rt = self.process.returncode
return rt if rt else 0
except:
if not self.process:
return 0

rt = self.process.returncode
return rt if rt else 0


class Procs:
Expand Down

0 comments on commit f346a8a

Please sign in to comment.