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


Groups > comp.lang.python > #28406

Re: sockets,threads and interupts

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'socket': 0.05; 'clause': 0.07; 'run,': 0.07; 'python': 0.09; 'sockets': 0.09; 'thread,': 0.09; 'cleanly': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'subject:threads': 0.16; 'threaded': 0.16; 'trap': 0.16; 'wrote:': 0.17; 'work.': 0.23; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'there.': 0.28; 'received:192.168.1.3': 0.29; 'wrap': 0.29; 'class': 0.29; 'up.': 0.31; 'could': 0.32; 'to:addr :python-list': 0.33; 'monitor': 0.33; "won't": 0.35; 'does': 0.37; 'uses': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'chance': 0.61; 'close': 0.63; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'guaranteed': 0.76; 'subject:,': 0.81; 'ports.': 0.84; 'reply- to:addr:python.org': 0.84; 'killed': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=W6e6pGqk c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=lR6CHUT36vYA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=FHbs8fUtD8AA:10 a=q1z7PMFHO0YA:10 a=qbg5HHIM_1kA:10 a=IKYNe_pnHKUA:10 a=v7ey3tHxI4MA:10 a=N4hpdHRZHgAA:10 a=sTOKQSFKWFoA:10 a=TFqcKDUXLT0A:10 a=RVSjMXkubmYA:10 a=haf4mBPXbV0A:10 a=YL8CwWjEfWsA:10 a=YsHCWR3NWtQA:10 a=7Cw1gAqGP1QwZJp7egwA:9 a=wPNLvfGTeEIA:10 a=P_PvJVi5qAcH1iYi:21 a=Y-z_TIqI_V8nCG2d:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Tue, 04 Sep 2012 18:06:17 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120824 Thunderbird/15.0
MIME-Version 1.0
To python-list@python.org
Subject Re: sockets,threads and interupts
References <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com>
In-Reply-To <4d1ffb61-38b6-42fb-9426-c1c7cb7038a0@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.181.1346778382.27098.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1346778382 news.xs4all.nl 6893 [2001:888:2000:d::a6]:48428
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28406

Show key headers only | View raw


On 04/09/2012 16:26, loial wrote:
> I have threaded python script that uses sockets to monitor network
> ports.
>
> I want to ensure that the socket is closed cleanly in all
> circumstances. This includes if the script is killed or interupted in
> some other way.
>
> As I understand it signal only works in the main thread, so how can I
> trap interupts in my threaded class and always ensure I close the
> socket? Using KeyboardInterupt does not seem to work.
>
You could wrap it in try...finally. The 'finally' clause is guaranteed
to be run, so you can close the sockets there.

However, if the script is just killed, then it won't get the chance to
tidy up.

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


Thread

sockets,threads and interupts loial <jldunn2000@gmail.com> - 2012-09-04 08:26 -0700
  Re: sockets,threads and interupts MRAB <python@mrabarnett.plus.com> - 2012-09-04 18:06 +0100
    Re: sockets,threads and interupts Grant Edwards <invalid@invalid.invalid> - 2012-09-04 18:11 +0000
      Re: sockets,threads and interupts Ramchandra Apte <maniandram01@gmail.com> - 2012-09-04 20:43 -0700
  Re: sockets,threads and interupts Dieter Maurer <dieter@handshake.de> - 2012-09-05 07:56 +0200
    Re: sockets,threads and interupts Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 05:54 -0700
      Re: sockets,threads and interupts Chris Angelico <rosuav@gmail.com> - 2012-09-05 23:04 +1000
        Re: sockets,threads and interupts Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 08:59 -0700
        Re: sockets,threads and interupts Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 08:59 -0700
          Re: sockets,threads and interupts Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 09:01 -0700
          Re: sockets,threads and interupts Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 09:01 -0700
      Re: sockets,threads and interupts Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-05 13:15 -0400
    Re: sockets,threads and interupts Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 05:54 -0700
  Re: sockets,threads and interupts Bryan <bryanjugglercryptographer@yahoo.com> - 2012-09-05 09:02 -0700

csiph-web