Python 有线程

Python with threads

我正在尝试使用 python 创建线程,它给了我一些错误:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)    self.run()
TypeError: 'module' object is not callable
  File "/usr/lib/python3.8/threading.py", line 870, in run

    self._target(*self._args, **self._kwargs)
TypeError: 'module' object is not callable

这是创建线程的 class:

import time
import threading

import eel

import backend.flowers as flower
import backend.python_video_stream.client as camera
import backend.senzori as senzori
import backend.senzori.temperature.temperature as temp

eel.init('frontend')

flower_thread = threading.Thread(target=flower)
flower_thread.start()


# for temperature
Temperature_thread = threading.Thread(target=temp)
Temperature_thread.start()

# for cameras
# camera_thread = threading.Thread(target=camera.client)

eel.start('View.html')

第一个线程显然工作正常,但仍然给我错误。这种情况怎么办?

如评论中所述,flowertemp是模块。 Threadtarget 参数需要一个 Callable 对象,通常是一个函数。

例如:

flower_thread = threading.Thread(target=flower.flowes)