2012-06-18 125 views
1

我正在使用Python + ZOPE/ZODB/Repoze BFG(首字母缩写词全部变得相当混乱)+贴图。python:是否有可能检测到我是否在paster shell?

我有一个贴纸壳,我可以做运行:

paster --plugin repoze.bfg bfgshell site.ini zodb 

,一切工作正常。然而,我有一堆监控的东西被打开 - 将调试信息打印到stdout的线程 - 当我刚刚启动shell时,并不需要运行。是否有可能以某种方式检测启动代码是否在shell中运行?因此,如果代码检测到外壳是而不是,它将启动这些线程,并且如果外壳,它就不会。

回答

1

bfgshell将在安装时使用IPython,否则将使用code InteractiveInterpreter。你可以测试任何一个:

import sys 

def in_shell(): 
    # Interactive prompt sets sys.ps1 
    if hasattr(sys, 'ps1'): 
     return True 

    # __IPYTHON__ is defined when running under IPython 
    return '__IPYTHON__' in __builtins__ 
+0

简而言之 - 谢谢! – Claudiu

相关问题