ファイルに特定の拡張子が付いている場合、ファイルの作成時にスクリプトを実行することはできますか?
その拡張機能を「バー」と呼びましょう
ファイル「foo.bar」を作成すると、スクリプトはそのファイルを入力として実行されます。
このファイルが保存されるたびに、ファイルに対しても実行されます。
それをしてもいいですか?はいの場合、どのように?そうでない場合、なぜですか?
注: これが不可能な理由について何らかの技術的な理由がある場合でも、非常に近いことはできますが、それもうまくいきます!
あなたはWerkzeugがすることをすることができます(このコードはリンクから直接コピーされました):
def _reloader_stat_loop(extra_files=None, interval=1):
"""When this function is run from the main thread, it will force other
threads to exit when any modules currently loaded change.
Copyright notice. This function is based on the autoreload.py from
the CherryPy trac which originated from WSGIKit which is now dead.
:param extra_files: a list of additional files it should watch.
"""
from itertools import chain
mtimes = {}
while 1:
for filename in chain(_iter_module_files(), extra_files or ()):
try:
mtime = os.stat(filename).st_mtime
except OSError:
continue
old_time = mtimes.get(filename)
if old_time is None:
mtimes[filename] = mtime
continue
elif mtime > old_time:
_log('info', ' * Detected change in %r, reloading' % filename)
sys.exit(3)
time.sleep(interval)
別のスレッドを生成する必要があります (これは Werkzeug が行うことです) が、pyinotify を追加したくない場合は、それでうまくいくはずです。