✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Start / stop external threads from usage.py (button)

Hello Dash community,

I’ve got a problem,

I’m trying to start and stop my threads with Buttons in usage.py
It work if my thread is in the main app (usage.py) but I’d like to externalise the threads.

A button:


A callback:

    Output('nav_power_btn', 'children'),
    [Input('nav_power_btn', 'n_clicks')])
def nav_power(n_clicks):
    # on initie le producer
    ip_address = ''
    port_eth = 13002
    thread_producer = Thread(target=Producer, args=(1, ip_address, port_eth))

    if n_clicks == 0:
        return 'START'

    elif n_clicks % 2 != 0:
        return 'START'

    elif n_clicks % 2 == 0:
        return 'STOP'

A Thread

import datetime
import socket
import sqlite3
import xml.etree.ElementTree as ET
from collections import deque
from threading import Thread

class Producer(Thread):
*get data from UDP device / While=True*

Currently I got exception
Exception in thread Thread-1772:

Traceback (most recent call last):
  File "C:\Users\aphilipp\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 926, in _bootstrap_inner
  File "C:\Users\aphilipp\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
TypeError: 'module' object is not callable

My question is:
Is it possible to externalise the Threads in independents files ? Must I use some tools like Celery / Redis to do it ?

Thanks for your time