I'm trying to write a simple script that connects to the freenode IRC network (irc.freenode.net on port 6667) to periodically post information on a channel. To do this, I am employing Python sockets. This has worked fine in the past, however now I am experiencing a strange problem: the socket takes an incredibly long time to connect if it does at all (it occasionally times out). However, this only happens when the script is run from a file. When typed into the interpretor directly it works fine:
>>> import socket
>>> def f():
>>> s = socket.socket()
>>> print("Connecting")
>>> s.connect(('irc.freenode.net', 6667))
>>> print("Connected")
>>> s.close()
>>> f()
The socket connects in about a second and everything is fine. However, if I put the following code in a file and run python test.py, it hangs on s.connect and occasionally times out:
import socket
s = socket.socket()
print("Connecting")
s.connect(('irc.freenode.net', 6667))
print("Connected")
s.close()
I have never had this problem before. This also occurs on other computers on my network (maybe it's network problem?). I'm using Python 3.2. Thanks.