uWSGI/Pylons 的开发模式(重新加载新代码)

发布于 2024-10-22 03:08:18 字数 412 浏览 2 评论 0原文

我有一个设置,这样 nginx 服务器将控制权传递给 uWsgi,它使用我的 xml 配置文件中的以下内容启动 pylons 应用程序:

<ini-paste>...</ini-paste>

一切都运行良好,我能够使用关联中的以下内容将其设置为调试模式ini 文件,例如:

debug = true

除调试模式外,仅打印出错误,并且不会在每次触摸文件时重新加载代码。如果我直接通过粘贴运行,我可以使用 --reload 选项,但是通过 uWsgi 会使事情变得复杂。

有谁知道如何告诉uWsgi告诉paste设置--reload选项,或者直接在paste .ini文件中执行此操作?

I have a setup such that an nginx server passes control off to uWsgi, which launches a pylons app using the following in my xml configuration file:

<ini-paste>...</ini-paste>

Everything is working nicely, and I was able to set it to debug mode using the following in the associated ini file, like:

debug = true

Except debug mode only prints out errors, and doesn't reload the code everytime a file has been touched. If I was running directly through paste, I could use the --reload option, but going through uWsgi complicates things.

Does anybody know of a way to tell uWsgi to tell paste to set the --reload option, or to do this directly in the paste .ini file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

許願樹丅啲祈禱 2024-10-29 03:08:19

我使用类似下面的代码来解决这个问题,在应用程序初始化时调用monitorFiles(...)方法,它监视文件,在看到更改时发送TERM信号。

我仍然更喜欢使用 Paster 的 --reload 参数的解决方案,因为我认为这个解决方案有错误:

    import os
    import time
    import signal

    from deepthought.system import deployment
    from multiprocessing.process import Process

    def monitorFiles():
        if deployment.getDeployment().dev and not FileMonitor.isRunning:
            monitor = FileMonitor(os.getpid())
            try: monitor.start()
            except: print "Something went wrong..."

    class FileMonitor(Process):

        isRunning = False

        def __init__(self, masterPid):
            self.updates = {}
            self.rootDir = deployment.rootDir() + "/src/python"
            self.skip = len(self.rootDir)
            self.masterPid = masterPid
            FileMonitor.isRunning = True
            Process.__init__(self)

        def run(self):
            while True:
                self._loop()
                time.sleep(5)

        def _loop(self):
            for root, _, files in os.walk(self.rootDir):
                for file in files:
                    if file.endswith(".py"):
                        self._monitorFile(root, file)

        def _monitorFile(self, root, file):
            mtime = os.path.getmtime("%s/%s" % (root, file))
            moduleName = "%s/%s" % (root[self.skip+1:], file[:-3])
            moduleName = moduleName.replace("/",".")
            if not moduleName in self.updates:
                self.updates[moduleName] = mtime
            elif self.updates[moduleName] < mtime:
                print "Change detected in %s" % moduleName
                self._restartWorker()
                self.updates[moduleName] = mtime

        def _restartWorker(self):
            os.kill(self.masterPid, signal.SIGTERM)

I used something like the following code to solve this, the monitorFiles(...) method is called on application initialization, and it monitors the files, sending the TERM signal when it sees a change.

I'd still much prefer a solution using paster's --reload argument, as I imagine this solution has bugs:

    import os
    import time
    import signal

    from deepthought.system import deployment
    from multiprocessing.process import Process

    def monitorFiles():
        if deployment.getDeployment().dev and not FileMonitor.isRunning:
            monitor = FileMonitor(os.getpid())
            try: monitor.start()
            except: print "Something went wrong..."

    class FileMonitor(Process):

        isRunning = False

        def __init__(self, masterPid):
            self.updates = {}
            self.rootDir = deployment.rootDir() + "/src/python"
            self.skip = len(self.rootDir)
            self.masterPid = masterPid
            FileMonitor.isRunning = True
            Process.__init__(self)

        def run(self):
            while True:
                self._loop()
                time.sleep(5)

        def _loop(self):
            for root, _, files in os.walk(self.rootDir):
                for file in files:
                    if file.endswith(".py"):
                        self._monitorFile(root, file)

        def _monitorFile(self, root, file):
            mtime = os.path.getmtime("%s/%s" % (root, file))
            moduleName = "%s/%s" % (root[self.skip+1:], file[:-3])
            moduleName = moduleName.replace("/",".")
            if not moduleName in self.updates:
                self.updates[moduleName] = mtime
            elif self.updates[moduleName] < mtime:
                print "Change detected in %s" % moduleName
                self._restartWorker()
                self.updates[moduleName] = mtime

        def _restartWorker(self):
            os.kill(self.masterPid, signal.SIGTERM)
柠檬 2024-10-29 03:08:19

使用0.9.7树中的信号框架

http://projects.unbit.it/uwsgi/wiki/ SignalFramework

自动重载的示例:

import uwsgi

uwsgi.register_signal(1, "", uwsgi.reload)
uwsgi.add_file_monitor(1, 'myfile.py')

def application(env, start_response):
    ...

Use the signal framework in 0.9.7 tree

http://projects.unbit.it/uwsgi/wiki/SignalFramework

An example of auto-reloading:

import uwsgi

uwsgi.register_signal(1, "", uwsgi.reload)
uwsgi.add_file_monitor(1, 'myfile.py')

def application(env, start_response):
    ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文