2016-06-01 15 views
0

ete3 packageで系統樹を生成するスクリプトを作成しました。このスクリプトはヘッドレスサーバーで実行されるため、xvfb-runhere)で起動する必要があります。xvfbで自分自身を呼び出すpythonスクリプト

xvfbで呼び出された場合(システムコールps)のスクリプトを設定しました。 xvfb-run(例えばpython script.py...)を使用せずにpythonスクリプトを起動する場合、元のスクリプト呼び出しからプロセスを強制終了して正しく再実行する方法がありますか(例えばxvfb-run python script.py...)?

os.system()と一緒に何かをハッキングしようとしましたが、psに電話しましたが、私は大したことはありません。誰にも何か提案はありますか?

答えて

1

私は何かを一緒に置くことができました、ちょうどcheck_xvfb()関数をスクリプトの先頭に追加してください。

def check_xvfb(): 
    """ 
    Use of the ete3 library from the command line requires an X11 server 
    which doesn't exist on this headless Ubuntu server. One way around this 
    is to use xvfb-run. This function checks that the script was properly 
    launched with xvfb-run; if not, it will relaunch it (with the same options) 
    and then terminate the previously called script 
                                      Parameters 
    ----------                                none 

    Returns 
    ------- 
    none 

    """ 

    # CHECK IF SCRIPT PROPERLY LAUNCHED 
    # see http://stackoverflow.com/a/6550543/1153897 for explanation of 'cat' 
    # grep -v ignores the ps -ef call since it'll match itself 
    comm = 'ps -ef | grep xvfb-run | grep %s | grep -v grep | cat' %os.path.splitext(os.path.basename(sys.argv[0]))[0] 
    output = subprocess.check_output(comm, shell=True) 

    if not len(output): # script not called properly 
     print 'script not called properly, retrying...' 
     comm_run = 'xvfb-run ' + ' '.join(sys.argv) 
     os.system(comm_run) # properly call script 
     sys.exit(0) 
    else: 
     print 'script called properly!' 
関連する問題