This repository was archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.py
More file actions
executable file
·51 lines (41 loc) · 1.41 KB
/
dev.py
File metadata and controls
executable file
·51 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#coding:utf-8
'''python2 code
author's email: chenyan@feling.net
运行dev.py,会调用相同路径下的httd4t.py, 在8888端口监听,
如果相同路径下有py文件发生改变,就重启httpd4t.py
需要第三方模块
easy_install watchdog
'''
import os, sys, time, subprocess
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s',
datefmt='%M:%S',
)
class Hander(FileSystemEventHandler):
def restart(self):
global process
process.kill()
process.wait()
process = subprocess.Popen(['python','httpd4t.py','8888'], stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
def on_any_event(self, event):
if event.src_path.endswith('.py'):
logging.info(event.src_path+' has been modified, restarting...')
self.restart()
def start():
observer = Observer()
observer.schedule(Hander(), '.', recursive=True)
observer.start()
logging.info('start watching...')
global process
process = subprocess.Popen(['python','httpd4t.py','8888'], stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
if __name__ == '__main__':
start()