tags:

views:

177

answers:

1

Pardon my ignorance as I'm still a beginner in coding.

I'm trying to convert a python script I wrote to a Windows executable program using py2exe. However, though I am able to successfully convert the script, the executable doesn't seem to be fully functional.

After much debugging, I have isolated the cause and the following code seems to be the problem

host = str(raw_input('Enter Host IP Address: ')) 
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((host, 5000))

The problem does not occur when the script is executed from Pydev itself and the script is able to run without problems. The windows executable which is a console application just hangs when trying to connect to another host.

Is this a known issue or am I doing something wrong? Any help is much appreciated.

+1  A: 

Hello!

Are you able to input the IP address? Reading that thread it seems that py2exe requires a special windows argument to launch a console. Otherwise, raw_input tries to read from the standard input, and hangs/crashes because it does not find anything.

Given the age of the thread, I checked py2exe doc: you might want to try to put your script in the console attribute.

I really think that the behavior is related to raw_input, and that it is not caused by the socket operation.

NicDumZ
Hello. I'm using the "console" argument in my setup.py and the console application prompts for input. If I were to comment out the socket operation and just make my script print the input (for the host's ip address), it would work fine. As such, I assumed it was due to the connect. :/
kouei
Then, since the connect is blocking, waiting for the other end to answer, you should try setting up a timeout on client_socket before trying to connect. (default timeout is None, which means that if your server is broken, the client will wait forever). If a "Timed out" SocketError breaks, it will mean that the Server is not listening / that the wrong address is used :)
NicDumZ