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


Groups > comp.lang.python > #50435

Re: How to clean up socket connection to printer

References <c124b305-e2de-4355-bd20-15d0f9a40b65@googlegroups.com> <f74f0fb1-c2d8-4640-ad03-89f81c55f23f@googlegroups.com>
Date 2013-07-11 20:13 +1000
Subject Re: How to clean up socket connection to printer
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4580.1373537630.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jul 11, 2013 at 7:28 PM, loial <jldunn2000@gmail.com> wrote:
> Replies to questions :
>
> 1. Does the printer accept connections again after some time?
>
> Yes, bit seems to vary how long that takes
>
> 2. Does the printer accept connections if you close and re-open the
> Python interpreter?
>
> Not after a Connection reset error. The script exits after trapping the "Connection reset by peer" error and it is only when a new instance of the script is kicked off that the "Connection refused" issue is encountered.
>

What's the network between you and the printer like? Are you, for
instance, going through an el cheapo NAT router? I've had some routers
that have a tendency to just randomly dump their NAT mappings (or so
it seems), which results in all manner of fun.

The "connection reset" error most likely means that you thought you
had a connection but the printer (or a router along the way, shouldn't
happen but see above) thought it didn't. You won't actually get the
error until you try to send some more data [1], which can result in
the variance in time. In fact, if the printer is indeed rebooting (as
per Ulrich's suggestion), you could get immediate success (reset,
reconnect, succeed), or you could get a delay of anything up to the
time it takes to reboot (if you "got in" straight after it went down).
What's the longest you've ever seen it take from conn reset to able to
connect again?

It's almost [2] certainly not that you're failing to properly close
the connection, though. I'd be inclined to simply code in a retry loop
(NOT instant, chances are you'll get some fast failures and you don't
want to spin; a progressive back-off delay is usually appropriate
here) and treat the failures as uninteresting.

ChrisA

[1] Unless you're using TCP keepalive, which you probably aren't.
[2] Insane stuff can be done, but hardware is presumed sane until
proven otherwise.

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


Thread

How to clean up socket connection to printer loial <jldunn2000@gmail.com> - 2013-07-09 02:39 -0700
  Re: How to clean up socket connection to printer Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-07-09 16:05 +0200
  Re: How to clean up socket connection to printer loial <jldunn2000@gmail.com> - 2013-07-11 02:28 -0700
    Re: How to clean up socket connection to printer Chris Angelico <rosuav@gmail.com> - 2013-07-11 20:13 +1000
  Re: How to clean up socket connection to printer loial <jldunn2000@gmail.com> - 2013-07-15 04:22 -0700

csiph-web