Auto-run a python script without reloading dependencies

天大地大妈咪最大 提交于 2020-01-16 05:13:13

问题


I’m working on a project that requires a lot algorithm development and data visualization. The workflow involves lots of small tweaks, with checks to see if the output matches expectations.

To fit that workflow, I’m trying to set up my work environment to be very responsive:

  1. Watch for file changes in given directory (like watchdog or tornado’s debug mode)
  2. On file change, re-run a given script (possibly the script that was modified)
  3. Do it in such a way that external modules (e.g. pandas, matplotlib) don’t need to be reloaded.
  4. If possible, do it in such a way that some large data inputs don’t need to be reloaded either.

Currently, I’m using watchdog’s watchemdo utility to re-run scripts every time they’re edited. The problem is that all the scripts have large-ish dependencies (matplotlib, etc.) that take a couple of seconds to load. It’s not much, but it really slows down the workflow.

Can anyone recommend an architecture/utility/etc. that satisfies 1, 2, 3, and (ideally) 4 as well?


回答1:


I figured it out. watchmedo was close, but wouldn't support requirements 3 and 4.

Here's a nice little script that meets all my requirements:

https://gist.github.com/abegong/bc4310de32ca25be73d8



来源:https://stackoverflow.com/questions/32997698/auto-run-a-python-script-without-reloading-dependencies

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!