无法访问作为 Windows 服务运行的 Python 服务器 [英] Cannot access Python server running as Windows service

查看:42
本文介绍了无法访问作为 Windows 服务运行的 Python 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Python TCP/IP 服务器供内部使用,使用 win32serviceutil/py2exe 创建 Windows 服务.

I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create a Windows service.

我将它安装在运行 Windows XP Pro SP3 的计算机上.但是,当它作为服务运行时,我无法连接到它.我可以确认它绑定到地址/端口,因为当我尝试将另一个应用程序绑定到该地址/端口时会发生冲突.此外,我检查了 Windows 防火墙设置并添加了适当的例外.如果我将服务器作为一个简单的控制台应用程序运行,一切都会按预期进行.但是,当我将其作为服务运行时,它不起作用.

I installed it on a computer running Windows XP Pro SP3. However, I can't connect to it when it's running as a service. I can confirm that it's binding to the address/port, because I get a conflict when I try to bind to that address/port with another application. Further, I have checked the Windows Firewall settings and have added appropriate exceptions. If I run the server as a simple console application, everything works as expected. However, when I run it as a service, it doesn't work.

我依稀记得以前遇到过这个问题,但我一生都记不起任何细节.

I vaguely remember running into this problem before, but for the life of me can't remember any of the details.

有什么建议吗?

推荐答案

首先,无论何时实现 Windows 服务,请务必添加适当的日志记录.

First of all, whenever you implement a Windows service, be sure to add proper logging.

我的工作线程因异常而终止,套接字操作无法在不阻塞的情况下完成."

My worker threads were terminating because of the exception, "The socket operation could not complete without blocking."

解决方案是在接受连接后简单地调用 sock.setblocking(1).

The solution was to simply call sock.setblocking(1) after accepting the connection.

这篇关于无法访问作为 Windows 服务运行的 Python 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆