It's a phenomenon about cpu intensive tasks when runing by python. I can not find a term to describe it.And English is not my mother tongue.
I have a program which is written by python. It is used to keep connection to the rabbitmq server,and do a task which is a cpu intensive task.
I use multithreading to run the cpu intensive task.and want to check the thread's status replace call method join.(for the reason:I should send heart beat by handle),just like the logic:
while True:
if thread.is_alive(): # status check method
time.sleep(5)
log.debug("need continue")
send_heartbeat()
else:
break
But it will lose rabbitmq's connection.
The rabbitmq loged: more than 60's not get the heartbeat from the connection,so close it .
And I tried to get more log:
- the log about "need continue" will not log out ,during the task(not all the time,just a part time of the task do) every 5 seconds.
It shows like,the child thread's method ,is_alive()
,block more than 5 seconds(what's more,it must will block more than 60 seconds,so that the rabbitmq server will close the conneciton)
Or maybe,the main thread, not get cpu execution right: the cpu execution is occupy by the child-thread,which is a cpu intensive task.The occupy time more than 60 seconds?
- I tried child process,the similar phenomenon shows.
It also blocked at some where,from the log time,not every 5 seconds.For used the multi-process,I thought it is blocked at the status check method.
Finally,I use multi-progress varibales to avoid use the status check method.And it run OK now.
But why, both the thread and process will block when doing some cpu intensive tasks(not all cpu intensive tasks show this)?
In my plain thinking:
the multi-thread just could not use multi-core, not means, cpu will not switch from one thread to another thread ?
Or, in multi-progress,Why will also block when call the status check method? also can not understand.
Could anyone tell me ,which kinds of cpu intensive task will show the phenomenon above, And why?
Or what key words should I search to get the reason above?
I had searched key words:cpu intensive task(In chinese), for I did not find a very precise word,I do not get any similer explains.
And I asked my colleague,alose not get any answer.
Thanks.