LoginSignup
4
4

More than 5 years have passed since last update.

すぐ死んでしまうgulp watchを蘇らせるスクリプト書いた

Last updated at Posted at 2015-08-21

gulp watchはすぐ死んでしまう上に例外がキャッチできないプラグインがいたりして、とてもイライラします。
なので、死んでもすぐゾンビのように復活させるPythonスクリプトを書きました

zombie.py
#!/usr/bin/env python
# -*- codint: utf-8 -*-

import sys
import signal
import subprocess

def rite(silent):
    print("start rite of gulp watch be zombie")
    print("if you want stop this program, Ctrl+C")
    cmd = "gulp watch"
    while True:
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        for line in iter(p.stdout.readline, b''):
            print(line.rstrip())
        if not silent:
            print("\a")
        print("\ngulp watch is dead. but revive soon.\n")

def signalHandler(signal, frame):
    print("\ngulp zombie killed")
    sys.exit(0)

if __name__ == '__main__':
    signal.signal(signal.SIGINT, signalHandler)
    try:
        sys.argv.index("-s")
        rite(True)
    except ValueError:
        rite(False)

これをgulpfile.jsと同じところに突っ込んで

python zombie.py

とすればgulp watchが死んでもゾンビのごとく復活します。
ちなみに通常ではビープ音で死亡を知らせてくれますが、

python zombie.py -s

としてやれば、静かにする事もできます。
通常のコマンド同様Ctrl+Cでこのゾンビを抹殺する事もできます。
Gist

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4