Why can't my simple pyramid app work with pexpect?

I have a very simple pyramid app that serves as a simple static page. Let's say its name mypyramid

and uses the port 9999

.


If I run mypyramid in another Linux console manually, then I can use the following code to print the html line.

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

      


But I want to run mypyramid in the application automatically.

So, in another application, I used pexpect

mypyramid to run and then tried to get the html string from http://localhost:9999/index.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 seems to have started successfully using pexpect

, as I can see the process listing is and has mypyramid started

been achieved.

However, the application hangs after trying to download url

, and I cannot get anything.


What solution? I mean, I thought I pexpect

would create a different process. If this is true then why is it stopping the html fetching?

+3


source to share


1 answer


My guess is that the child returned by pexpect.spawn needs to communicate. He tries to write, but nobody reads, so the application stops. (I'm only guessing).



If you don't have a reason to use pexpect (which you probably don't if you're not communicating with the child process), why don't you just go for a standard module sub-process?

0


source







All Articles