簡體   English   中英

為什么我的簡單金字塔應用程序無法與pexpect一起使用?

[英]Why my simple pyramid application cannot work with pexpect?

我有一個非常簡單的金字塔應用程序,它提供一個簡單的靜態頁面。 假設它的名字是mypyramid並使用端口9999


如果我手動在另一個Linux控制台中啟動mypyramid ,那么我可以使用以下代碼打印出html字符串。

if __name__ == "__main__":
    import urllib2
    print 'trying to download url'
    response = urllib2.urlopen('http://localhost:9999/index.html')
    html = response.read()
    print html

但我想自動在應用程序中啟動mypyramid

所以在我的另一個應用程序中,我使用pexpect啟動mypyramid ,然后嘗試從http://localhost:9999/index.html獲取html字符串。

def _start_mypyramid():
    p = pexpect.spawn(command='./mypyramid')
    return p

if __name__ == "__main__":
    p = _start_mypyramid()
    print p
    print 'mypyramid started'
    import urllib2
    print 'trying to download url'
    response = urllib2.urlopen('http://localhost:9999/index.html')
    html = response.read()
    print html

似乎mypyramid已成功使用pexpect啟動,因為我可以看到該過程的打印和mypyramid started已經mypyramid started

但是,應用程序只是在trying to download url掛起 ,我無法得到任何東西。


解決辦法是什么? 我的意思是我認為pexpect會創造另一個過程。 如果這是真的,那么為什么它會停止檢索html?

我的猜測是pexpect.spawn返回的孩子需要溝通。 它試圖寫但沒有人讀,所以應用程序停止。 (我只是猜測)。

如果您沒有任何理由使用pexpect(如果您不與子進程通信,則可能沒有),為什么不進入標准模塊子進程?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM