暂停python函数中的线程

暂停python函数中的线程,python,multithreading,python-2.7,Python,Multithreading,Python 2.7,我在python程序中使用线程。我的问题是如何暂停线程/从另一个函数停止它,然后再次重新启动它 我用于线程的方法如下所示: import threading def motor(): #I want to stop the checkID thread here x=1 # starts the motor # I want to restart the checkID() thread as the motor function execution is now complet

我在python程序中使用线程。我的问题是如何暂停线程/从另一个函数停止它,然后再次重新启动它

我用于线程的方法如下所示:

import threading

def motor():
  #I want to stop the checkID thread here
  x=1 # starts the motor 
  # I want to restart the checkID() thread as the motor function execution is now complete


def checkID():

  if (ID==matched):
     motor()
  else:
      print 'id not matched'


def main():
  checkIDthread = threading.Thread(target=checkID)
  checkIDthread.start()
main()
因此,我希望checID函数一直在运行。但是,当我调用motor()函数来启动一个电机时,我想暂停checkID()线程,然后在motor()函数结束时,在电机函数执行完成后再次重新启动它


有人能告诉我怎么做吗?

等一下,您现在正在从
checkID
调用
motor
,这意味着该功能在
motor
退出之前不会继续。问题已解决?@bereal否,checkid()将继续再次运行,因为它被称为线程。
motor
在同一个线程中被调用,因为它是从
checkid
@bereal调用的,但我有一个稍长版本的这个程序,我在程序中看到,即使motor()仍在运行,checkid也会再次开始运行。我需要再检查一次。谢谢。您是在主线程的其他地方还是在另一个线程中调用
motor()
?在这种情况下,您需要在
motor()
开头使用
acquire()
锁定
,在结尾使用
release()
锁定-您可以使用with语句来锁定。