By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,172 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,172 IT Pros & Developers. It's quick & easy.

select() problem, not timing out

P: n/a
Hi all,
I am having trouble with a program that ran fine on

Python 2.0 (#0, Mar 1 2001, 01:47:55)
[GCC 2.95.1 19990816 (release)] on linux2

but will not work on

Python 2.3.2 (#1, Oct 8 2003, 17:33:47)
[GCC 3.3.2 20030908 (Debian prerelease)] on linux2

These are part of Familiar Linux running on a iPAQ.

The program has a button to cause a packet to be sent to a server,
the program also has a thread to read packets from the server.
I send a packet, I get one back, pretty simple.

I am using select() to wait for packets
and it isn't functioning as expected.

select() doesn't return until I have sent a packet
even though I am using a short timeout (1 second)

So whats happening is I send a packet,
select() returns but I have no input yet,
then I have to send a second packet
then select returns and I can read the
response to the first packet.

Here's a snippet of the code

from sys import argv
from gtk import *
import socket
import time
import threading
import select
....
my_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
my_sock.bind(('', MY_PORT))

class readerthread(threading.Thread):
def __init__(self):
self._stopevent = threading.Event()
print "thread init"
threading.Thread.__init__(self, name="readerthread")

def run(self):
ilist = []
ilist.append(my_sock)
print "readerthread - my_sock %d" % my_sock.fileno()
while not self._stopevent.isSet():

print "about to select"
il,ol,el = select(ilist,[],[],1)

# read from the socket, etc
if il != []:
data, addr = my_sock.recvfrom(1024)
print "recv() Data length %d" %len(data)
print "recv() Data %s" % data
else:
print "No input from select"

def join(self,timeout=None):
"""
Stop the thread
"""
self._stopevent.set()
threading.Thread.join(self, timeout)
....
def button_cb(button):
my_sock.sendto(data, (SERVERADDR, SERVERPORT))
....

I first posted this problem back on March 11.
I thought it was due to switching to a Win XP system,
now it seems to be due to switch Python versions.

I have tried all the sugestions made back in March,
none fixed the problem.

I have tried
ilist.append(my_sock.fileno()) - instead of ilist.append(my_sock)
also
il,ol,el = select([my_sock.fileno()],[],[],1) and
il,ol,el = select([my_sock],[],[],1)
instead of il,ol,el = select(ilist,[],[],1)

Do I need to do something to set a default timeout?
Does the default timeout override the select() timeout?

Any help would be appreciated.
Thanks (sorry for the long post),
David Shifflett
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <da*************************@posting.google.com> ,
sh*******@nps.navy.mil (D. Shifflett) wrote:
Hi all,
I am having trouble with a program that ran fine on

Python 2.0 (#0, Mar 1 2001, 01:47:55)
[GCC 2.95.1 19990816 (release)] on linux2

but will not work on

Python 2.3.2 (#1, Oct 8 2003, 17:33:47)
[GCC 3.3.2 20030908 (Debian prerelease)] on linux2

These are part of Familiar Linux running on a iPAQ.

The program has a button to cause a packet to be sent to a server,
the program also has a thread to read packets from the server.
I send a packet, I get one back, pretty simple.

I am using select() to wait for packets
and it isn't functioning as expected.

select() doesn't return until I have sent a packet
even though I am using a short timeout (1 second)


You could be running into some kind of bug in select,
but of course statistically the odds are overwhelming
that the bug is in your application.

The code you posted looked OK to me on casual examination,
but it raises some questions I can't answer - for example,
unless I missed something, the "select" function might have
come from "from gtk import *"?

If no one turns up who recognizes this problem, do you
think you could post a complete, minimal program
that exhibits this behavior - no "...", no gtk, etc.?
Might try this with and without threads to see if it
has anything to do with your problem.

Donn Cave, do**@u.washington.edu
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.