py2exe - 连接到套接字时生成的可执行文件冻结

发布于 2024-07-23 21:00:26 字数 478 浏览 5 评论 0原文

请原谅我的无知,因为我仍然是编码的初学者。

我正在尝试使用 py2exe 将我编写的 python 脚本转换为 Windows 可执行程序。 然而,尽管我能够成功转换脚本,但可执行文件似乎并不能完全发挥作用。

经过多次调试,我已经隔离了原因,以下代码似乎是问题所在。

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

当从 Pydev 本身执行脚本并且脚本能够正常运行时,不会出现问题。 Windows 可执行文件是一个控制台应用程序,当尝试连接到另一台主机时,它只是挂起

这是一个已知问题还是我做错了什么? 任何帮助深表感谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2024-07-30 21:00:26

可以输入IP地址吗? 阅读 该线程 似乎 py2exe 需要一个特殊的windows 启动控制台的参数。 否则, raw_input 尝试从标准输入读取,并挂起/崩溃,因为它找不到任何内容。

鉴于线程的年龄,我检查了 py2exe doc:您可能想尝试将您的脚本放入 console 属性中。

我确实认为该行为与 raw_input 有关,并且它不是由套接字操作引起的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文