Search code examples
pythonpython-multithreading

Python with threads


I am trying to create threads with python and it gives me some errors:

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

And this is the class that creates the threads:

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')

The fist thread is working apparently, but still give me errors. What should I do in this situation?


Solution

  • As mentioned in the comments, flower and temp are modules. The target parameter of Thread expects a Callable object, typically a function.

    For example:

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