【问题标题】:TextMate Python bundle non-blockingTextMate Python 捆绑非阻塞
【发布时间】:2011-07-11 07:53:30
【问题描述】:

我在 TextMate 中创建了一个包,用于重新启动当前 Django 项目的相关主管进程。在 Python 解释器中运行代码成功地重新启动进程而不会阻塞,但是当我将它用作 TextMate 包(设置为每次保存 .py 文件时运行)时,它会阻塞 GUI 约 3 秒。有什么办法可以避免这种情况吗?

代码如下:

#!/usr/bin/env python
import os
import subprocess
import threading

projname = os.environ.get('TM_PROJECT_DIRECTORY', '').rpartition('/')[2]


def restart_proj(projname=None):
    """ Restart a supervisor instance.
    Assumes that the name of the supervisor instance is the basename for
    TM_PROJECT_DIRECTORY.
    """
    if projname:
        subprocess.Popen('$HOME/.virtualenvs/supervisor/bin/' \
                         'supervisorctl restart {0}'.format(projname),
                         shell=True, stdout=open('/dev/null', 'w'))

t = threading.Thread(target=restart_proj, args=(projname, ))
t.start()

【问题讨论】:

    标签: python django textmate textmatebundles supervisord


    【解决方案1】:

    这可能为时已晚,但您可能希望通过在 Popen 参数中设置 close_fds=True 来提前关闭它。指定它后,它不会等待响应。

    subprocess.Popen('$HOME/.virtualenvs/supervisor/bin/' \
                         'supervisorctl restart {0}'.format(projname),
                         shell=True, close_fds=True, stdout=open('/dev/null', 'w'))
    

    【讨论】:

    • 我不再使用这个捆绑包了。但你的评估似乎有道理!
    猜你喜欢
    • 2011-03-12
    • 2011-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    相关资源
    最近更新 更多