[英]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.