想多线程周期调用 kafka_producer(),代码如下,点击 pushButton_kafka 按钮,能够调用kafka_producer_start_thread(),并且打印new,但无法调用timer,求解
global timer
self.timer = QTimer(self)
self.timer.timeout.connect(self.kafka_producer) # 计时器挂接到槽:update
self.pushButton_kafka.clicked.connect(self.kafka_producer_start)
def kafka_producer_start(self):
try:
global kafka_producer_num
for kafka_producer_thread_i in range(4):
_thread.start_new_thread(self.kafka_producer_start_thread,())
except Exception as e:
traceback.print_exc()
def kafka_producer_start_thread(self):
print("new")
self.timer.start(50)
def kafka_producer(self):
print("here")
package com.steven.demo;
import java.lang.Runnable;
import java.lang.Thread;
public class ThreadTest02 {
public static void main(String[] args) {
//创建线程:
Thread thread = new Thread(new Teacher());
//启动线程
thread.start();
}
}
class Teacher implements Runnable {
//重写Run方法
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("Run:"+i);
}
}
}