Python executes cmd command shutdown with multithreading timing

Source: Internet
Author: User

The OS module can be used to execute the cmd command, which can be used to achieve a timed shutdown, but in the process of waiting for shutdown can not do nothing, so multi-threading comes in handy.

#! /usr/bin/env python#coding=utf-8# here need to introduce three modules import time, OS, sched, Easygui, Thread    # The first parameter determines when a task is Returns the number of seconds 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 = $):    # Enter is used to schedule the occurrence of an event, starting from now on in nth Seconds    Schedule.enter (inc, 0, Perform_command, (CMD, Inc)    # continues to run until the scheduled time queue becomes empty     schedule.run ()     thread.exit_thread ()    if __name__ = = ' __main__ ':        print ("Show Time After Seconds:")     Thread.start_new_thread (Reminder, ("Shutdown-s", 10))    print ' In this waiting process does not delay us doing something else '


Python executes cmd command shutdown with multithreading timing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.