0
我在TextMate中創建了一個包,用於重新啓動當前的Django項目的關聯Supervisor進程。在Python解釋器中運行代碼可以成功重啓進程而不會阻塞,但是當我將它作爲TextMate包使用時(每次保存.py文件時都設置爲運行),它會阻塞GUI約3秒。有什麼辦法可以避免這種情況嗎?TextMate Python包非阻塞
下面的代碼是什麼樣子:
#!/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()
我不再使用這個包。但你的評估似乎是合理的! – jmagnusson