Python Win32:错误

约翰·兰博

我试图使python脚本作为Windows服务运行。

为了稍微了解一下,我从这里获取了这段代码

我已经安装了以下东西:

  1. python2.7(64位)
  2. pywin32.exe。(64位)

但是,该脚本无法找到以下内容:

  1. win32event.CreateEvent
  2. win32event.WAIT_OBJECT_0
  3. win32event.WaitForSingleObject(self.hWaitStop,5000)
  4. win32service.SERVICE_STOP_PENDING)
  5. win32event.SetEvent

虽然我没有导入任何错误消息,但是我收到了上述功能的错误消息。

import win32service  
import win32serviceutil  
import win32event  

class PySvc(win32serviceutil.ServiceFramework):  
# you can NET START/STOP the service by the following name  
_svc_name_ = "PySvc"  
# this text shows up as the service name in the Service  
# Control Manager (SCM)  
_svc_display_name_ = "Python Test Service"  
# this text shows up as the description in the SCM  
_svc_description_ = "This service writes stuff to a file"  

def __init__(self, args):  
    win32serviceutil.ServiceFramework.__init__(self,args)  
    # create an event to listen for stop requests on  
    self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)  

# core logic of the service     
def SvcDoRun(self):  
    import servicemanager  

    f = open('test.dat', 'w+')  
    rc = None  

    # if the stop event hasn't been fired keep looping  
    while rc != win32event.WAIT_OBJECT_0:  
        f.write('TEST DATA\n')  
        f.flush()  
        # block for 5 seconds and listen for a stop event  
        rc = win32event.WaitForSingleObject(self.hWaitStop, 5000)  

    f.write('SHUTTING DOWN\n')  
    f.close()  

# called when we're being shut down      
def SvcStop(self):  
    # tell the SCM we're shutting down  
    self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)  
    # fire the stop event  
    win32event.SetEvent(self.hWaitStop)  

if __name__ == '__main__':  
    win32serviceutil.HandleCommandLine(PySvc)
约翰·兰博

我试图从sourceforge.net站点重新安装win32。但这没有奏效。

最终,我尝试了pip命令,它的工作原理很吸引人。

pip install pypiwin32

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Python win32 ShellExecute错误31:“连接到系统的设备无法运行。”

来自分类Dev

无法安装Python win32库?

来自分类Dev

使用IPython嵌入Python:WindowsError:[错误193]%1不是有效的Win32应用程序

来自分类Dev

用Nuitka编译任何Python程序后,我得到“不是有效的win32应用程序”错误

来自分类Dev

在Python中使用WIN32 API CreateProcessAsUser

来自分类Dev

Windows OS上的Python和Win32之间的IPC

来自分类Dev

使用python win32向excel添加注释

来自分类Dev

使用 win32 python 拒绝 Word 访问

来自分类Dev

Python win32 api drawText() 和 SetTextColor

来自分类Dev

C ++,Win32错误

来自分类Dev

OSError:[WinError 193]%1不是有效的Win32应用程序错误,在Windows上通过Selenium和Python使用GeckoDriver和Firefox

来自分类Dev

python输出信息中的win32 ro win64?

来自分类Dev

python输出信息中的win32 ro win64?

来自分类Dev

在Win32上的Python中使用.NET?python.net是否可行?

来自分类Dev

在python中加载DLL时出错,不是有效的Win32应用程序

来自分类Dev

How to dismiss a dialog box displayed by MS Word when openning document in Python/Win32

来自分类Dev

从弹出菜单中选择项目Win32 API Python

来自分类Dev

Python:DLL加载失败:%1不是有效的Win32应用程序

来自分类Dev

Python [WinError 193]%1不是有效的Win32应用程序

来自分类Dev

遍历Excel列A,使用Python win32写入列B

来自分类Dev

调用dll函数,该函数需要从python指向句柄(win32)的指针

来自分类Dev

Windows操作系统上的Python和Win32之间的IPC

来自分类Dev

Win32的Cortana

来自分类Dev

Win32线程

来自分类Dev

win32 ExportAsFixedFormat

来自分类Dev

如何处理Win32错误消息的占位符?

来自分类Dev

win32 GetConsoleMode()错误代码6

来自分类Dev

Unity Android构建错误WIN32异常ZipAlign

来自分类Dev

OPENCV链接错误-Win32和VS2012

Related 相关文章

  1. 1

    Python win32 ShellExecute错误31:“连接到系统的设备无法运行。”

  2. 2

    无法安装Python win32库?

  3. 3

    使用IPython嵌入Python:WindowsError:[错误193]%1不是有效的Win32应用程序

  4. 4

    用Nuitka编译任何Python程序后,我得到“不是有效的win32应用程序”错误

  5. 5

    在Python中使用WIN32 API CreateProcessAsUser

  6. 6

    Windows OS上的Python和Win32之间的IPC

  7. 7

    使用python win32向excel添加注释

  8. 8

    使用 win32 python 拒绝 Word 访问

  9. 9

    Python win32 api drawText() 和 SetTextColor

  10. 10

    C ++,Win32错误

  11. 11

    OSError:[WinError 193]%1不是有效的Win32应用程序错误,在Windows上通过Selenium和Python使用GeckoDriver和Firefox

  12. 12

    python输出信息中的win32 ro win64?

  13. 13

    python输出信息中的win32 ro win64?

  14. 14

    在Win32上的Python中使用.NET?python.net是否可行?

  15. 15

    在python中加载DLL时出错,不是有效的Win32应用程序

  16. 16

    How to dismiss a dialog box displayed by MS Word when openning document in Python/Win32

  17. 17

    从弹出菜单中选择项目Win32 API Python

  18. 18

    Python:DLL加载失败:%1不是有效的Win32应用程序

  19. 19

    Python [WinError 193]%1不是有效的Win32应用程序

  20. 20

    遍历Excel列A,使用Python win32写入列B

  21. 21

    调用dll函数,该函数需要从python指向句柄(win32)的指针

  22. 22

    Windows操作系统上的Python和Win32之间的IPC

  23. 23

    Win32的Cortana

  24. 24

    Win32线程

  25. 25

    win32 ExportAsFixedFormat

  26. 26

    如何处理Win32错误消息的占位符?

  27. 27

    win32 GetConsoleMode()错误代码6

  28. 28

    Unity Android构建错误WIN32异常ZipAlign

  29. 29

    OPENCV链接错误-Win32和VS2012

热门标签

归档