python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?

python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?,第1张

概述QProcess.pid()的文档说: Returns the native process identifier for the running process, if available. If no process is currently running, 0 is returned. 这是什么意思? 这段代码用来解释我的困惑.我使用的是Python 2.7.9,PyQt 4和Window QProcess.pid()的文档说:

Returns the native process IDentifIEr for the running process,if available. If no process is currently running,0 is returned.

这是什么意思?

这段代码用来解释我的困惑.我使用的是Python 2.7.9,PyQt 4和windows 7:

import  sys,os,timefrom PyQt4.QtCore import *from PyQt4.QtGui import *class testLaunch(QWidget):    def __init__(self):        QWidget.__init__(self)        self.process = QProcess(self)        self.process.start('calc')        self.process.waitForStarted(1000)        print "PID:",int(self.process.pID())if __name__ == "__main__":    app = QApplication(sys.argv)    main = testLaunch()    main.show()    sys.exit(app.exec_())

这将按预期启动windows计算器应用程序.在任务管理器中,它显示以下内容:

这显示我的PID为8304.虽然我的应用程序的print语句显示:

PID: 44353984

代表了什么?它与任务管理器报告的8304 PID相比如何?

解决方法 在Unix系统上,pID将是一个qint64,但在windows上它将是这样的结构:

typedef struct _PROCESS_informatION {  HANDLE hProcess;  HANDLE hThread;  DWORD  DWProcessID;  DWORD  DWThreadID;} PROCESS_informatION,*LPPROCESS_informatION;

PyQt将为这样的结构返回一个sip.voIDptr,这就是为什么当你用int()转换它时你会看到这个奇怪的值.你想要的实际pID是DWProcessID,所以你需要使用像ctypes这样的东西来提取它.

这是一些完全未经测试的代码,可以完成这项工作:

import ctypesclass WinProcInfo(ctypes.Structure):    _fIElds_ = [        ('hProcess',ctypes.wintypes.HANDLE),('hThread',('DWProcessID',ctypes.wintypes.DWORD),('DWThreadID',]LPWinProcInfo = ctypes.POINTER(WinProcInfo)lp = ctypes.cast(int(self.process.pID()),LPWinProcInfo)print(lp.contents.DWProcessID)
总结

以上是内存溢出为你收集整理的python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?全部内容,希望文章能够帮你解决python – 在Windows上使用pyqt时,QProcess.pid()结果代表什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1193449.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存