strange socket behaviour

Joe Wong joewong at mango.cc
Tue Jun 1 22:37:21 EDT 2004


Hello,

 I have a short program that the client make a connection to server, a thread is then created to poll any data sent from the server. The main thread will close the socket after 5 seconds. Here are the code:

from socket import *
import select
import threading
import time

def poll(c):
    i, o, e = select.select([c], [], [])
    if not i:
        print "time out"
        return
    print i
    data = i[0].recv(1024)
    print "data: ", data

if __name__=="__main__":
    c = socket(AF_INET, SOCK_STREAM)
    c.connect(('192.168.100.74', 8888))
    th=threading.Thread(None, poll, "", (c, ))
    th.setDaemon(1)
    th.start()

    time.sleep(5)
    c.shutdown(2)
    c.close()
    th.join()
    print "completed"

On Windows, as soon as client socket 'c' is closed, the select() call returns. However, on Linux, the program seems blocking forever ( may be I am not patient to wait ). Is there anything wrong with my code?

Regards,

-- Wong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040602/62a745f3/attachment.html>


More information about the Python-list mailing list