使用Python进行热重装/交换 [英] hot reloading / swapping with Python

查看:267
本文介绍了使用Python进行热重装/交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望代码更改在开发期间立即生效.如何检测已更改的文件并将其重新加载到正在运行的Python(2.7)应用程序中?

I want code changes to take effect immediately during development. How can I detect changed files and reload them in the running Python (2.7) application?

阅读完"Ivo van der Wijk"链接的页面后,我认为最好在代码更改时重新启动Web应用程序,就像Django一样.因此,实际的问题是:如何监视文件修改?

After reading the pages linked by 'Ivo van der Wijk', I think it would be best to restart the web application when code changes - like Django does. So the actual question is: How to monitor file modifications?

推荐答案

已问过此问题编号

This question has been asked a number of times

您可以为此使用reload(module),但要注意讨厌的副作用.例如,现有代码将基于原始代码,不会神奇地添加新的属性或基类.

You can use reload(module) for this, but beware of nasty side effects. For example, existing code will be based on the original code, it will not magically get new attributes or baseclasses added.

这篇关于使用Python进行热重装/交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆