How does Python multitasking happen?
This article mainly explains "how Python multitasking happens". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how Python multitasking happens.
Preparatory work
Increase the output of details during the execution of the program.
Results of execution in a single task
WT: >
RT:int DataArray::getDataSize ()
RT: {
RT: return 5
RT:}
RT::----data_size=5
RT:int DataArray::getData (0)
RT: {
RT: if (index > = 0 & & index
< m_dataSize) RT: { RT: return m_buffer[0];, value =0 RT: } RT:} RT:int DataArray::getData(1) RT:{ RT: if(index >= 0 & & index
< m_dataSize) RT: { RT: return m_buffer[1];, value =1 RT: } RT:} RT:int DataArray::getData(2) RT:{ RT: if(index >= 0 & & index
< m_dataSize) RT: { RT: return m_buffer[2];, value =2 RT: } RT:} RT:int DataArray::getData(3) RT:{ RT: if(index >= 0 & & index
< m_dataSize) RT: { RT: return m_buffer[3];, value =3 RT: } RT:} RT:int DataArray::getData(4) RT:{ RT: if(index >= 0 & & index
< m_dataSize) RT: { RT: return m_buffer[4];, value =4 RT: } RT:} RT:----total=10 上面的输出只是写五个数,读五个数的部分,但是可以看出写数据处理(WT) 完全结束以后,读数据处理(RT)才开始执行。这是数据处理正确进行的必要条件,记住这一点。 多任务(线程)条件下的执行结果 RT:>> ReadData:WT: