Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21150

RE: Python - CGI-BIN - Apache Timeout Problem

Subject RE: Python - CGI-BIN - Apache Timeout Problem
Date 2012-03-02 13:43 -0800
References <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> <CAMZYqRTXSHD9DnjVVj87vVVi21ePQyOaqjTYH6h=iQGDN2XULA@mail.gmail.com>
From "Sean Cavanaugh (scavanau)" <scavanau@cisco.com>
Newsgroups comp.lang.python
Message-ID <mailman.355.1330724483.3037.python-list@python.org> (permalink)

Show all headers | View raw


Hey All,

So maybe this part is important (after doing some troubleshooting)  hopefully not everyone has beers in hand already since its Friday :-) 

The way the code works if you want to send through the firewall (i.e.   SERVER->FIREWALL->SERVER)  I split the process into two threads.  One is listening on the egress, then I send on the ingress.  The main waits until the thread finishes (it times out after 2 seconds).  I had to do this b/c scapy (the library I used) won't let me send pcaps while I receive them.  This lets me see packets on both sides (i.e. did that sort of internet traffic go through the firewall).   The reason I think this could be a problem is when I ran a test where I sent to the firewall (rather than through it) and my program does not need to thread the webserver works fine......   

Suggestions anyone?

-S

-----Original Message-----
From: chris@rebertia.com [mailto:chris@rebertia.com] On Behalf Of Chris Rebert
Sent: Friday, March 02, 2012 3:23 PM
To: Sean Cavanaugh (scavanau)
Cc: python-list@python.org
Subject: Re: Python - CGI-BIN - Apache Timeout Problem

On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau)
<scavanau@cisco.com> wrote:
<snip>
> THE PROBLEM:
>
> When I execute the scripts from the command line (#python main.py) it
> generates it fine (albeit slowly), it prints all the html code out including
> the script.  The ‘core’ part of the script dumbed down to the lowest level
> is->
>
>         proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'],
> stdout=subprocess.PIPE)
>         output = proc.stdout.read()

Note the red warning box about possible deadlock with .stdout.read()
and friends:
http://docs.python.org/library/subprocess.html#popen-objects

>         print output
>         proc.stdout.close()

As the docs advise, try using .communicate()
[http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate
] instead:
    proc = subprocess.Popen(…)
    out, err = proc.communicate()
    print out

> When I open main.py and execute the script it just hangs… it seems to
> execute the script (I see pcap fires on the interface that I am testing on
> the firewall) but its not executing correctly… or loading the entire
> webpage…the webpage keeps chugging along and eventually gives me an error
> timeout.

The hanging makes me suspect that the aforementioned deadlock is occurring.

Cheers,
Chris
--
http://chrisrebert.com

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: Python - CGI-BIN - Apache Timeout Problem "Sean Cavanaugh (scavanau)" <scavanau@cisco.com> - 2012-03-02 13:43 -0800

csiph-web