Message1865
This does uncover an error handling problem in Jython, but I wouldn't say this is 'working' in Python. If you add the except socket.error clause to the read loop(as I've done below), you'll see in Python that the read loop is blocking waiting for a receive in the thread, and then when the same socket tries to send from another place, Python gets an error and prints the following:
!!
(10054, 'Connection reset by peer')
done.
!!
(10054, 'Connection reset by peer')
done.
!!
(10054, 'Connection reset by peer')
done.
''
''
''
Jython is blocking at the receive in the thread in the class, and then when the same socket tries to send from another location, the program hangs and doesn't raise the socket.error. Jython does need to address the socket.error. I remember there were similar problems with error handling in 2.2 for sockets. I did try to write the same code in Java, but I wasn't even able to write it with just one socket reading in a thread while the same socket is writing from another part of the same program at the same time. All you need to do, though, to make this work is to create another socket for your send.
Charlie, et all, I will attempt to have Jython throw a socket.error in this case, but I may need some guidance.
The updated script is as follows, I don't know how to add an attachment to a comment, though. If it doesn't come out well, I will send it to the dev forum.
import socket
import time
import threading
class Reader(threading.Thread):
def __init__(this, udp_sock):
threading.Thread.__init__(this)
this.udp_sock = udp_sock
this.running = 0
def run(this):
this.running = 1
while this.running:
try:
text, addr = this.udp_sock.recvfrom(8000)
print text
except socket.error, e:
print e
udp_sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_sock.bind(("", 5555))
reader = Reader(udp_sock)
reader.start()
while not reader.running:
time.sleep(1.0)
while 1:
time.sleep(1.0)
print "!!"
udp_sock.sendto("hi", ('localhost', 5556))
print " done."
|
|
Date |
User |
Action |
Args |
2008-02-20 17:18:00 | admin | link | issue1782548 messages |
2008-02-20 17:18:00 | admin | create | |
|