Skip to content

Commit

Permalink
Revert "Use Popen to start processes (joh#46)"
Browse files Browse the repository at this point in the history
This commit introduced a bug where the command would only run once if
multiple files are changed at the same time. This revert closes joh#49.

This reverts commit ea2cf37.
  • Loading branch information
joh committed Mar 16, 2017
1 parent b2cb0f1 commit 85de2f2
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions whenchanged/whenchanged.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def __init__(self, files, command, recursive=False, run_once=False, run_at_start
self.last_run = 0

self.observer = Observer(timeout=0.1)
self.process = None

for p in self.paths:
if os.path.isdir(p):
Expand All @@ -75,27 +74,12 @@ def run_command(self, thefile):
if self.run_once:
if os.path.exists(thefile) and os.path.getmtime(thefile) < self.last_run:
return

if self.is_running_process():
self.stop_current_process()

new_command = []
for item in self.command:
new_command.append(item.replace('%f', thefile))

self.start_process(new_command)

def start_process(self, command):
is_shell_command = len(command) == 1
self.process = subprocess.Popen(command, shell=is_shell_command)
subprocess.call(new_command, shell=(len(new_command) == 1))
self.last_run = time.time()

def stop_current_process(self):
self.process.kill()

def is_running_process(self):
return bool(self.process) and self.process.poll() is None

def is_interested(self, path):
if self.exclude.match(path):
return False
Expand Down

0 comments on commit 85de2f2

Please sign in to comment.