from pynput import keyboard from multiprocessing import Process import multiprocessing, psutil def run(index): # index = 1 while True: index += 1 print('进程在运行!', index) def listen_1(): with keyboard.Listener(on_press=on_press, on_release=None) as (listener): listener.join() def on_press(key): global pid try: if str(key) == 'Key.end': pause = psutil.Process(pid) pause.suspend() print('暂停运行') if str(key) == 'Key.home': pause = psutil.Process(pid) pause.resume() print('恢复运行') except AttributeError: print('', end='') if __name__ == '__main__': multiprocessing.freeze_support() p = Process(target=run, args=(100000000000000000000,)) p.start() pid = p.pid listen_1()
标签:__,index,pause,Process,pid,开启,键盘,控制线,print From: https://www.cnblogs.com/zwnsyw/p/17444458.html