Non blocking wait in python

前端 未结 4 1508
忘掉有多难
忘掉有多难 2021-01-04 05:43

in python, if i want to keep a process or thread running forever, i can typically do this with an empty while loop:

while 1:
    pass
         


        
4条回答
  •  无人及你
    2021-01-04 06:31

    What's the issue with sleeping for a very brief period of time? 1 millisecond is close to an eternity to a modern computer. Provided you don't have thousands of these threads (which it sounds like you don't), then there is NOTHING wrong with sleeping for one, ten, ten thousand, or ten million milliseconds every iteration through the loop. The CPU won't even notice this little blip.

提交回复
热议问题