Opening sockets on multiple ports

Alain Désilets alain.desilets at nrc.ca
Tue Nov 13 10:48:55 EST 2001


Alain Désilets wrote:

> Found what the problem was.
>
> Basically, the client could only connect to the TO_SERVER port, because that was the first port that the server listened to using the
> SocketServer.serve_forever() method. For some reason, when I later invoked SocketServer.server_forever() on the FROM_SERVER port, it never got
> to listen to that port, eventhough it was running in a separate thread from the first one.
>
> I get around the problem by not using server_forever. Instead, I alternate between the two SocketServer instances and manually invoke
> handle_request to handle a single request on each.
>
> Attached is the modified code.

I'm such a dunce!

I just figured out why the REAL problem in my original scripts.

I thought I was running the two SocketServer.serve_forever()  in different threads, but in fact, I was starting both threads by invoking their
run() method directly. The proper way to start a thread (as I have now discovered) is to invoke threading.Thread.start() which invokes
threading.Thread.run() in a new thread. Invoking threading.Thread.run() directly doesn't run it in a new thread.


Alain





More information about the Python-list mailing list