Skip to content
Advertisement

time.sleep does not work for multithreaded

I was trying to multithread the code for “Suspend / Hibernate pc with python” provided by Ronan Paixão when I find that time.sleep() does not suspend the thread that run pywin32 module.

>>> Warning! The following code will put Windows to sleep <<<

JavaScript

The print function did waited for time.sleep(), but the Windows was immediately put to sleep. What happened?

Advertisement

Answer

You’re passing the buffer argument in the call to Thread incorrectly, so it’s only sleeping for 1.0 second. You need to add a comma , at the end of value for the args keyword argument like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement