python - Q进程执行时间

标签 python pyqt pyside qprocess

我想测量 QProcess 对象的执行时间。

PySide 中是否有用于执行时间测量的内部属性、方法或对象?

目前的方法是使用 time.time() 从外部对其进行测量。

示例代码:

from PySide import QtCore
import time

p = QtCore.QProcess()
start_time = time.time()
p.start('ping -n 5 127.0.0.1 >nul')
p.waitForFinished(-1)
end_time = time.time() - start_time

print(end_time)

最佳答案

您可以通过以下方式执行此操作。这使用系统 time 命令来获取执行时间。

from PySide import QtCore
import time

p = QtCore.QProcess()
p.start('time -p ping -n 5 127.0.0.1 >nul')
p.waitForFinished(-1)
stdOut = p.readAllStandardOutput()
print(stdOut)
#TODO you will have to regex the stdOut to get the values you want.

这是另一种方法:

from PySide import QtCore
import time

timer = QtCore.QTime()


def handle_proc_stop(*vargs):
    procTime = timer.elapsed()
    print("Process took {} miliseconds".format(procTime))

p = QtCore.QProcess()
p.started.connect(timer.start)
p.finished.connect(handle_proc_stop)
p.start('ping -n 5 127.0.0.1 >nul')
p.waitForFinished(-1)

关于python - Q进程执行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37783271/

相关文章:

python - 使用 python 和 selenium 在 IE 中的新选项卡和选项卡切换中打开一个 Url

python - 具有加州住房数据的神经网络

python - 如何停止从任务运行的 Airflow DAG

python - 选中 CheckBox 后在窗口中添加新的 TextBox

qt - QMime数据 : setting and getting the right MIME types for arbitrary widgets

python - 从外部 qss 文件读取 pyqt 样式表

python - 如何在 Python 中捕获 EINTR?

python - 为什么QWidget在继承时表现不同

python - 使用 PySide 清理 Maya 中的可停靠窗口

python - 如何使用 QComboBox.setPlaceholderText?