Browse code

Fix an issue in 'watch' and 'preview' where main process is terminated with child processes still running

fhemberger authored on 12/09/2011 at 19:36:14
Showing 1 changed files
... ...
@@ -60,12 +60,11 @@ task :watch do
60 60
   compassPid = Process.spawn("compass watch")
61 61
 
62 62
   trap("INT") {
63
-	Process.kill(9, jekyllPid)
64
-	Process.kill(9, compassPid)
65
-	exit 0
63
+    [jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
64
+    exit 0
66 65
   }
67 66
 
68
-  Process.wait
67
+  [jekyllPid, compassPid].each { |pid| Process.wait(pid) }
69 68
 end
70 69
 
71 70
 desc "preview the site in a web browser"
... ...
@@ -77,13 +76,11 @@ task :preview do
77 77
   rackupPid = Process.spawn("rackup --port #{server_port}")
78 78
 
79 79
   trap("INT") {
80
-	Process.kill(9, jekyllPid)
81
-	Process.kill(9, compassPid)
82
-	Process.kill(9, rackupPid)
83
-	exit 0
80
+    [jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
81
+    exit 0
84 82
   }
85 83
 
86
-  Process.wait
84
+  [jekyllPid, compassPid, rackupPid].each { |pid| Process.wait(pid) }
87 85
 end
88 86
 
89 87
 # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")