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


Groups > comp.lang.python > #97237

Re: ConnectionError handling problem

Newsgroups comp.lang.python
Date 2015-09-29 23:04 -0700
References <550e9854-1247-4f6b-b9c7-7c8d7ea6ae37@googlegroups.com> <mailman.165.1443165885.28679.python-list@python.org>
Message-ID <ff56fdf3-e40b-4ebf-8f4a-524f3ce61fbd@googlegroups.com> (permalink)
Subject Re: ConnectionError handling problem
From shiva upreti <katewinslet626@gmail.com>

Show all headers | View raw


On Friday, September 25, 2015 at 12:55:01 PM UTC+5:30, Cameron Simpson wrote:
> On 24Sep2015 22:46, shiva upreti <katewinslet626@gmail.com> wrote:
> >On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote:
> >> On 24Sep2015 20:57, shiva upreti <katewinslet626@gmail.com> wrote:
> >> >Thank you Cameron.
> >> >I think the problem with my code is that it just hangs without raising any 
> >> >exceptions. And as mentioned by Laura above that when I press CTRL+C, it 
> >> >just catches that exception and prints ConnectionError which is definitely 
> >> >a lie in this case as you mentioned.
> 
> Ok. You original code says:
> 
>   try:
>     r=requests.post(url, data=query_args)
>   except:
>     print "Connection error"
> 
> and presumably we think your code is hanging inside the requests.post call? You 
> should probably try to verify that, because if it is elsewhere you need to 
> figure out where (lots of print statements is a first start on that).
> 
> I would open two terminals. Run your program until it hangs in one.
> 
> While it is hung, examine the network status. I'll presume you're on a UNIX 
> system of some kind, probably Linux? If not it may be harder (or just require 
> someone other than me).
> 
> If it is hung in the .post call, quite possibly it has an established connecion 
> to the target server - maybe that server is hanging.
> 
> The shell command:
> 
>   netstat -rn | fgrep 172.16.68.6 | fgrep 8090
> 
> will show every connection to your server hosting the URL 
> "http://172.16.68.6:8090/login.xml". That will tell you if you have a 
> connection (if you are the only person doing the connecting from your machine).
> 
> If you have the "lsof" program (possibly in /usr/sbin, so "/usr/sbin/lsof") you 
> can also examine the state of your hung Python program. This:
> 
>   lsof -p 12345
> 
> will report on the open files and network connections of the process with pid 
> 12345. Adjust to suit: you can find your program's pid ("process id") with the 
> "ps" command, or by backgrounding your program an issuing the "jobs" command, 
> which should show the process id more directly.
> 
> Cheers,
> Cameron Simpson <cs@zip.com.au>

Hi Cameron.
Yes I use ubuntu 14.04. I will try what you suggested. But I cant understand one thing, for whatever reason the script is hanging, why does it resumes almost instantaneously when I press CTRL+C.
Thanks.

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


Thread

Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-09-25 09:25 +1000
  Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 20:57 -0700
    Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-09-25 14:59 +1000
      Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 22:46 -0700
        Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-09-25 17:24 +1000
          Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-29 23:04 -0700
            Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-10-01 07:30 +1000
            Re: ConnectionError handling problem Laura Creighton <lac@openend.se> - 2015-09-30 23:56 +0200

csiph-web