程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python uses multithreading to execute CMD command to shut down

編輯:Python

utilize os The module can perform cmd command , This can be used to achieve a timed shutdown , However, you can't do nothing while waiting for the shutdown , So multithreading comes in handy .

 #! /usr/bin/env python
#coding=utf-8
# Three modules need to be introduced here
import time, os, sched, easygui, thread
# The first parameter determines the time of the task , Returns the number of seconds elapsed from a specific time to the present
# The second parameter measures time in some artificial way
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
os.system(cmd)
def reminder(cmd, inc = 60):
# enter Used to schedule an event , From now on n Start in seconds
schedule.enter(inc, 0, perform_command, (cmd, inc))
# Keep running , Until the scheduled time queue becomes empty
schedule.run()
thread.exit_thread()
if __name__=='__main__':
print("show time after 10 seconds:")
thread.start_new_thread(reminder, ("shutdown -s", 10))
print' In the process of waiting, it doesn't delay us to do something else ' </pre> 

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved