是否可以通過使用多線程模塊從其他正在運行的線程釋放鎖?我正在努力的用例是暫時強制一個線程阻塞並稍後解除阻塞。從另一個線程釋放解釋器鎖/強制另一個線程阻塞
from multiprocessing import Process
import time
def loop_forever():
while True:
pass
def pause_evaluation():
#Some code here that will force the other thread to release its GIL
def resume_evaluation():
#Some code here that will allow other thread to reacquire its GIL
def kill_evaluation():
global p_1
p_1.terminate()
def control_evaluation():
pause_evaluation()
time.sleep(30)
resume_evaluation()
time.sleep(30)
kill_evaluation()
p_1 = Process(target = loop_forever)
p_2 = Process(target = control_evaluation)
p_1.start()
p_2.start()
p_1.join()
p_2.join()
什麼是'多線程',它來自哪裏?這不是標準的庫模塊。 –
對不起,我的意思是多處理 – btomtom5
好的,所以當你說「線程」時,你的意思是「過程」,對吧? –