# coding: utf8
import threading
import time
# 真正要执行的函数
def t1():
print ('ok')
# 每隔10秒钟执行
def t2():
while 1:
t1()
time.sleep(10)
if __name__ == '__main__':
t = threading.Thread(target=t2)
t.start()
# 此处写你主线程要处理的事情.....
t.join()
在pyqt下实现
#后台循环进程
def t2():
while(1):
while(ex.checkbox_cycle1.isChecked()):
print('ddd')
time.sleep(1)
print('xxx')
time.sleep(1)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = CANCtrlWindow()
t = threading.Thread(target=t2)
t.start()
# 此处写你主线程要处理的事情.....
sys.exit(app.exec_())
t.join()