How does a threading.Thread yield the rest of its quantum in Python?

后端 未结 3 1644
深忆病人
深忆病人 2020-12-08 01:53

I\'ve got a thread that\'s polling a piece of hardware.

while not hardware_is_ready():
    pass
process_data_from_hardware()

But there are

3条回答
  •  伪装坚强ぢ
    2020-12-08 02:51

    Read up on the Global Interpreter Lock (GIL).

    For example: http://jessenoller.com/2009/02/01/python-threads-and-the-global-interpreter-lock/

    Also: http://www.pyzine.com/Issue001/Section_Articles/article_ThreadingGlobalInterpreter.html

    Do this in your code if you must do Busy Waiting (e.g. polling a device).

    time.sleep( 0.0001 )
    

    This will yield to the thread scheduler.

    Also, I collected some notes and references in http://homepage.mac.com/s_lott/iblog/architecture/C551260341/E20081031204203/index.html

提交回复
热议问题