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


Groups > comp.lang.python > #44699

Re: socket programming

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.081
X-Spam-Evidence '*H*': 0.84; '*S*': 0.00; 'python': 0.11; 'windows': 0.15; 'block.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'loops': 0.16; 'lurking': 0.16; 'subject:programming': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'machine': 0.22; "haven't": 0.24; 'task': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'second,': 0.31; 'option': 0.32; 'open': 0.33; 'url:python': 0.33; 'problem': 0.35; "can't": 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'machine.': 0.36; 'done': 0.36; 'url:org': 0.36; 'should': 0.36; 'manager': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'ensure': 0.60; 'easy': 0.60; 'url:3': 0.61; 'first': 0.61; 'close': 0.67; 'anything.': 0.68; 'interrupt': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=tl5WBfQ+05S0RCR2Oel35h/no0XtN9D1PE9D6Hdf9+E=; b=NQeXWP18o6eAcOojfwYTmj630MdrNk+IaWmMly4JZbkEY9SsoCvI/M2ypAE7o762Dj IEnHjzIved7gSKyHs3ErJ94uTOu+5AJ7I04pGU+fjLBu+OZkhswJsYig/8FrduQh50hH C1siUucFVSiFnAC6xWZtPQk2d/mP5QgzyFbXmVZ1O9rJzCSaChqmX0fjnWynGZvND8Cm nLA85lEAX/pxNGYD5fe6o1+aUv7XIeJKbTvNRFhatRKCU+z4rm6cuqa7ug9Fl5jfpZL8 HTLTjKvHMrNaOIyp9qLzS9GuYec3UmbOrHKduv6KeBC1dJxlEj0KckgUtC94LxmbeTPp Qjog==
MIME-Version 1.0
X-Received by 10.58.15.193 with SMTP id z1mr4422524vec.40.1367634218329; Fri, 03 May 2013 19:23:38 -0700 (PDT)
In-Reply-To <4aef55bd-f550-4a3d-b11a-285b6fa9892b@googlegroups.com>
References <4aef55bd-f550-4a3d-b11a-285b6fa9892b@googlegroups.com>
Date Sat, 4 May 2013 12:23:38 +1000
Subject Re: socket programming
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
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.1282.1367634220.3114.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1367634220 news.xs4all.nl 15938 [2001:888:2000:d::a6]:48331
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44699

Show key headers only | View raw


On Sat, May 4, 2013 at 12:13 PM, Pedro <pedro@ncf.ca> wrote:
> First - this code constantly loops around an open socket. Is there a way to use something like an interrupt so I don't have to loop constantly to monitor the socket?

The accept() call should block. It's not going to spin or anything. If
you need to monitor multiple sockets, have a look at select().

> Second, if any part of the program fails execution (crashes) the port often remains open on my windows machine and the only way to close it that i know of is through task manager or by rebooting the machine. Is there an easy way around this problem ? If I don't close the port the program can't open it again and crashes.

It remains for a short time to ensure that there's no lurking
connections. You can bypass this check by setting the SO_REUSEADDR
option - lemme hunt that down in the Python docs, haven't done that in
Python for a while...

http://docs.python.org/3.3/library/socket.html#socket.socket.setsockopt

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

That should do the job.

ChrisA

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


Thread

socket programming Pedro <pedro@ncf.ca> - 2013-05-03 19:13 -0700
  Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-04 12:23 +1000
    Re: socket programming Pedro <pedro@ncf.ca> - 2013-05-03 20:37 -0700
      Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-04 13:56 +1000
        Re: socket programming Pedro <pedro@ncf.ca> - 2013-05-03 21:03 -0700
  Re: socket programming Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-05-04 11:37 +0200
    Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-04 20:00 +1000
    Re: socket programming Pedro <pedro@ncf.ca> - 2013-05-06 08:54 -0700
      Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-07 02:05 +1000
      Re: socket programming Arnaud Delobelle <arnodel@gmail.com> - 2013-05-06 19:54 +0100

csiph-web