python-multithreading

Python – threading assert group is None when creating a custom Thread Class

Python – threading assert group is None when creating a custom Thread Class Question: I wanted to create a custom Thread class that is able to propagate an exception it comes across to the main thread. My implementation is as follows: class VerseThread(threading.Thread): def __init__(self, args): super().__init__(self, args=args) # self.scraper = scraper def run(self): self.exc …

Total answers: 1

Multiprocess web application using API or MessageQueue

Multiprocess web application using API or MessageQueue Question: I’m testing multiprocessing using apply_async. However, it looks like each apply_async is called from MainProcess and it’s not exactly asynchronous. Each function is called only after previous one is finished. I’m not sure what I’m missing here. I’m using Windows with Python 3.8, so it’s using the …

Total answers: 1

Python pyqt6 window blocks main loop

Python pyqt6 window blocks main loop Question: I have a small program that does something, but i want to "switch modes", for now i press a key and an input prompts on the console, but to make it easier i want to make a window with pyqt6, the problem is that the window blocks or …

Total answers: 1

Start listening to kafka in a parallel stream when starting a django project

Start listening to kafka in a parallel stream when starting a django project Question: I want to run a file that listens to kafka in a parallel stream with a django project. My manage.py file import asyncio import os import sys import multiprocessing as mt from kafka.run_kafka import run_kafka def main(): """Run administrative tasks.""" os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, …

Total answers: 1

Python 3 – How to terminate a thread instantly?

Python 3 – How to terminate a thread instantly? Question: In my code (a complex GUI application with Tkinter) I have a thread defined in a custom object (a progress bar). It runs a function with a while cicle like this: def Start(self): while self.is_active==True: do it.. time.sleep(1) do it.. time.sleep(1) def Stop(self): self.is_active=False It …

Total answers: 2

Difficulty instantiating a subclass [object has no attribute]

Difficulty instantiating a subclass [object has no attribute] Question: I get two types of errors when I try to start or initiate the member function temp_controll from the subclass Temperature_Controll. The issue is that the while loops are started in a new thread. I am having trouble passing the modbus client connection to the member …

Total answers: 3

how can I control three different threads using threading in python?

How can I control three different threads using threading in Python? Question: I have thread1, thread2 and thread3, global variable x and three different functions to increment x, import threading import time #check = threading.Condition() x=1 def add_by1(): global x x+=1 time.sleep(1) print(x) def add_by2(): x+=2 time.sleep(1) print(x) def add_by3(): x+=3 time.sleep(1) print(x) if __name__==__main__: …

Total answers: 1

Python ThreadPoolExecutor: How to evaluate what caused a timeout

Python ThreadPoolExecutor: How to evaluate what caused a timeout Question: Given the following simple method that causes a TimeoutError at some point. How can I determine what were the conditions (e.g. arguments or something else) that caused the timeout? In [82]: def f(i): …: print(i) …: if i == 2: time.sleep(1) …: return "done" …: …

Total answers: 1

Threading in Pygame causing Memory leak

Threading in Pygame causing Memory leak Question: I am creating an Asteroids Game. the game is intended for use over long periods of time. on startup (using pycharms debugg tool) i am using roughly 30.1 MB of system memory. however i have noticed that while running, it increases by roughly 0.1 MB every second (with …

Total answers: 1