在 Windows 中暂停进程 [英] Pausing a process in Windows

查看:42
本文介绍了在 Windows 中暂停进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Windows 上的 ffmpeg 制作一个漂亮的小型 Python GUI 前端(专门设计用于将视频转换为 iPhone 友好格式并自动将其导入 iTunes 并标记它),我希望它能够正常工作您可以暂停该过程并根据需要恢复它.

I'm making a nice little Python GUI frontend for ffmpeg on Windows (one that is specifically designed to convert videos to an iPhone-friendly format and automatically import it to iTunes and tag it), and I want it to work so that you can pause the process and resume it if you want.

由于我将 ffmpeg 作为一个单独的进程启动,显而易见的解决方案是让程序挂起进程(我知道这在 Windows 中是可能的,进程资源管理器可以做到),但我不知道该怎么做它.有谁知道如何在 Python 中做到这一点?

Since I start ffmpeg as a separate process, the obvious solution would be for the program to suspend the process (which I know is possible in Windows, Process Explorer can do it), but I can't figure out how to do it. Does anyone have any idea how to do this in Python?

推荐答案

您可以使用 psutil ( https://github.com/giampaolo/psutil ):

You can easily do this by using psutil ( https://github.com/giampaolo/psutil ):

import psutil
pid = 1034  # replace this with the pid of your process
p = psutil.Process(pid)
p.suspend()

...恢复它:

p.resume()

在内部,这是通过使用 SuspendThread() 和 ResumeThread() Windows 系统调用在 C 中实现的.

Internally this is implemented in C by using SuspendThread() and ResumeThread() Windows system calls.

这篇关于在 Windows 中暂停进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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