简体   繁体   English

自动运行python脚本而无需重新加载依赖项

[英]Auto-run a python script without reloading dependencies

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 (eg pandas, matplotlib) don't need to be reloaded. 这样做的方式是不需要重新加载外部模块(例如pandas,matplotlib)。
  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. 目前,我正在使用watchdog的watchemdo实用程序来在每次编辑脚本时重新运行它们。 The problem is that all the scripts have large-ish dependencies (matplotlib, etc.) that take a couple of seconds to load. 问题在于所有脚本都具有很大的依赖项(matplotlib等),这些依赖项需要花费几秒钟来加载。 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、2、3和(理想情况下)4?

I figured it out. 我想到了。 watchmedo was close, but wouldn't support requirements 3 and 4. watchmedo很接近,但不支持要求3和4。

Here's a nice little script that meets all my requirements: 这是一个可以满足我所有要求的漂亮小脚本:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM