4,119 questions
0
votes
0
answers
24
views
Python server that simulates an ML training process with Flask and SocketIO (issues with multithreading & multiprocessing)
I am trying to create a client-server app in which the client can send a HTTP request with files to the server to start a process of training an AI model. I want the client to be able to get updates ...
0
votes
1
answer
174
views
How to Gracefully Stop a Thread Inside a Spark foreachBatch Callback
I'm using a thread from the threading package to launch a function that performs spark streaming. I want to stop the thread inside the process function when a condition is met.
import threading
import ...
0
votes
1
answer
44
views
The main loop is not working when I am using multiprocessing in python
I am making a speech recognition program in python where I want that when I say "above", it will continuously run the loop to press the down key until I again don't say above, but now after ...
1
vote
1
answer
228
views
Stopping a dash server inside a thread does not work
I'm trying to stop a dash server within a thread, but it doesn't work:
Here's a minor example of the issue :
import threading
import requests
from dash import Dash, html
from flask import Flask, ...
0
votes
1
answer
65
views
Using a variable between two files
I have been trying multiple ways to try and get a variable from file#1 to file#2 but every time I import file#1 to file#2 it seems like file#2 fails to work.
I think this is due to file#2 being run in ...
0
votes
1
answer
152
views
i am making a face authentication program using opencv and deepface model in python
I wrote this function but is some times give me this error
"Authenticated as Muhammad Zair
[ WARN:[email protected]] global cap_msmf.cpp:1768 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. ...
0
votes
1
answer
53
views
Python Multithreading - Unterminated Processes
The code below, which I’ve modeled after the code I'm working on and simplified for the purpose of this question, doesn’t seems to be using p.join() properly to manage the processes created by p.start(...
1
vote
2
answers
124
views
Python Pool.apply_async() is returning None type objects
I have a 4GB+ file in which each line represents a very nested JSON string. An example of what the file looks like would be below:
{"core":{"id":"1","field1":{&...
0
votes
0
answers
71
views
'Conflicting' threads?
I am trying to understand threading and if/when its use is the most appropriate in context of a project I am working on. I am running this on a RPi 4, using python.
I have a fairly large script, two ...
0
votes
1
answer
154
views
Multithreading in Python not working correctly with Raspberry Pi
I'm using a Raspberry Pi 4B and a development kit which contains sensors and sends the data via BLE.
The project consists of a Raspberry Pi working as an Edge device where it reads sensor data via BLE,...
0
votes
0
answers
57
views
python concurrent.futures.ThreadPool blocking
I have the code below. read_sql is method on my DBReader class and it's using pd.read_sql.
Im parallelizing sql selects to the Postgres sql table.
import pandas as pd
def read_sql(self, sql, params =...
0
votes
0
answers
52
views
Python parallelism and /dev/ttyS0 sharing
I don't know how to make those two functions (which are called in the code below at the end) parallel. If I do multitasking or multiprocessing I came across errors regarding multiple port access. If I ...
0
votes
0
answers
80
views
ThreadPoolExecutor submit method thread creation error
I'm running a stream data processor on AWS ECS (EC2) by polling for messages in an SQS queue.
I use a ThreadPool as shown below (some of the code is omitted for brevity):
def process_messages(self, ...
0
votes
0
answers
201
views
Python ThreadingHTTPServer interacting with the main thread how to?
I am using Python 3.9 on a Raspberry Pi. I'm using a http.server.ThreadingHTTPServer so that I can run other tasks concurrently while handling HTTP requests. My needs are simple, so I don't want to ...
0
votes
1
answer
264
views
Why threading is much faster than asyncio when processing multiple files in my case
I'm experimenting with asyncio and threading to figure out which mechanism I should choose in processing a large number of files. The experiment is simple that I just want to read the files and add ...
-1
votes
1
answer
139
views
Why does a thread started inside PyGame GUI event loop slow down the GUI?
Some time ago I posted a problem about starting a thread inside a GUI loop, in which commands should run in parallel to the GUI event/drawing loop. This was supposed to be a measurement loop, which ...
0
votes
0
answers
108
views
Segfault when running thread in C program after converting from Python
I'm attempting to convert a Python script to C to improve its performance. The Python script involves threading, and I've translated it to C using an AI. However, when I compile and run the C script, ...
-1
votes
1
answer
62
views
Thread is not starting when calling a func
I'm working on a program to check many things periodically, and give me back data on a dashboard I made using tkinter. So, to ease the whole thread starting and Stopping threads, I created a Timer ...
1
vote
1
answer
116
views
Terminating threads in Python using threading.Event in a class [closed]
I have a Python program that uses fairly long-lived synchronous calls so things are wrapped in threads. Here's a rough MVP:
class MyClass:
processor = None
def __init__(self):
self....
0
votes
0
answers
22
views
Waiting for input from user using threads
I'm writing a client-server trivia game in python.
In the game, i want the user to have an option to enter input as long as he is playing.
Once the game ends (someone has won), he can no longer enter ...
1
vote
1
answer
240
views
Is asyncio in Python user-level threading model, cooperative scheduling?
I have been working for a long time with asyncio in Python, however I would like to clarify some thoughts on how asyncio actually works. I will break down my thoughts so that I can give context and ...
1
vote
0
answers
208
views
How to do multithreading in python for Raspberry pi
I was trying to make a project related to cv in which i want to send a video stream got from camera of raspberry pi to a different laptop along with the objects detected in the frames.
each frame ...
0
votes
1
answer
40
views
Why don't my threads make my script run a shorter time?
import re
import concurrent.futures
import time
setting1 = 101
setting2 = 321
setting3 = None
threads = 1000
start = time.perf_counter()
def load_keywords(keyword_file):
with open(keyword_file,...
0
votes
0
answers
27
views
Execution Python coroutine as background task in new Thread [duplicate]
I've code which looks like this way:
class Service:
async def publish(file_obj):
"""Sending file_obj to s3"""
def render_pdf(data: dict):
&...
1
vote
0
answers
219
views
Are Python's set[int] add/remove operations thread-safe?
Is the following Python code thread-safe? More precisely, under what conditions (Python implementations, versions, GIL presence, etc) is it guaranteed that KeyError will never happen and every item ...
1
vote
1
answer
27
views
Multiple threading.Threads created using loop inside class can´t store right parameters
I wrote a Threader class using the threading module that creates multiple threads to perform a task (function) on a list of elements. I´m passing slices of said list into a threading.Thread object ...
0
votes
1
answer
19
views
How to wait for a threaded api to finish?
I have this api that takes some inputs, and the code only has this line (except the import demo_v1 line):
demo_v1.main(image file, text file, integer)
Instead of manually writing the inputs for ...
0
votes
1
answer
316
views
Does pyodbc support multiprocessing?
The intent of the code below is to perform several database updates in parallel using pyodbc and mysql. Question: are the connections opened independently and in parallel? Will this code work or I ...
0
votes
1
answer
181
views
multiple locks in Python
In my Python3.12 code I have three threads in which the first thread T1 is a consumer, the second thread T2 is a producer, and the third thread T3 is a logger.
However, I have three additional ...
0
votes
0
answers
48
views
Python Background Thread Timer
def run_timer(duration):
import threading
import time
import sys
class Timer:
def __init__(self , duration):
self.duration = duration
self.remaining_time = duration
...
0
votes
1
answer
58
views
In ThreadPoolExecutor, socket.bind() is blocking without "Address already in use"
I'm writing a Python program using socket and tested listening the same port twice, using ThreadPoolExecutor.
This is a minimal program that reproduces my problem:
import socket
import time
import ...
0
votes
1
answer
440
views
How can I interrupt or send signals to python Threads without cooperation from the thread?
Previously I thought this wasn't possible to non-cooperatively interrupt a Thread in Python. A example might be the main thread asking to immediately cancel other theads in the process. But, from the ...
3
votes
1
answer
385
views
Can a data race occur when multiple threads access the same Numpy array?
My Python program has multiple threads accessing the same Numpy array instance. Since Numpy releases the GIL, these threads can end up accessing the array simultaneously.
If the threads are ...
0
votes
0
answers
46
views
Why is there a large ploting delay/lag in my real-time serial port ploting app after more than 10000 datapoints reading?
I am trying to write a real-time serial data reading and ploting APP, which read data from a arduino UNO board. But there is a problem that after more 10000 dataponits readout, the ploting presents a ...
1
vote
1
answer
43
views
Why does the python client socket receiving a reply but still throw the exception in some threadings?
This is my python code. It is a pinger client.It would send a messeng to the server and expect to receive the reply which capitalize the letters in 1 seconds.
from socket import *
import threading
...
0
votes
0
answers
48
views
Re-play slow motion doesn't play anything
The code below selects and plays in slow motion the last 8 seconds of a video.
Problem:
When the the button clean is pressed, it resets the video path, and allows for selecting a new video (path) by ...
0
votes
0
answers
97
views
I have encountered a wall while using customtkinter and threading together
So the thing is that I have to run a for loop and it takes some time to run, so I made a loading screen in a frame in customtkinter for my app. It goes like this-
import customtkinter
from PIL import ...
0
votes
0
answers
83
views
Is there a way to pause and restart a thread or kill a thread and start it again?
The project I am working on involves threading using a while loop which web scrapes stock prices from a website and plots this on a matplotlib graph.
I am now trying enable the user to change the ...
0
votes
1
answer
68
views
How to switch between Text widget contents with multiple buttons?
I want to make app to read log files from FTP server - when user clicks button, it connects to FTP, changes directory and reads data every 1sec. If data changed (new logs appeared), then it adds it to ...
0
votes
0
answers
77
views
cannot pickle '_mysql_connector.MySQL' object
when i receiving statistics from RS485,i want to save it in my MySQL database at the same time,as well as draw a plot by the statistics.As the threading in python can not satisfy my demand of ...
-2
votes
1
answer
138
views
How can I make a tkinter inaccessible while it is minimized after iconify is run?
I am attempting to open a tkinter window simultaneously with a pygame window, and I have scoured everywhere and come up with this code which I have trimmed so that it is a minimum viable product with ...
1
vote
0
answers
34
views
Python subprocess threading with conole log not immediately updating
I'd like to write a function where I can input any CLI command, which then runs inside it's own subprocess, and which logs it's output to a file and to the terminal.
The execution of a command can ...
-1
votes
1
answer
24
views
python threading library Perform a new activity [closed]
please attention to this simple program:
from time import sleep
from threading import Thread
def fun1():
sleep(10)
thread1 = Thread(target = fun1)
thread1.start()
#sign
sleep(100)
print("hello&...
0
votes
5
answers
197
views
Why is threading.Condition.notfiy_all not trigger that a waiting thread is continued?
With the following code, I want to show how to synchronize with a thread.
I want to have a separate thread that updates an image.
From these images, I want to have an asynchronous generator.
The ...
0
votes
1
answer
138
views
Python asyncio: Do I Need Synchronization Primitives for Shared Variables When Using run_in_executor with ThreadPoolExecutor?
I'm working with Python's asyncio and triing to understand the run_in_executor function with the default ThreadPoolExecutor to handle blocking tasks asynchronously. My concern is regarding accessing ...
0
votes
2
answers
270
views
ThreadPoolExecutor too fast for CPU bound task
I'm trying to understand how ThreadPoolExecutor and ProcessPoolExecutors work. My assumption for this test was that CPU-bound tasks such as increasing a counter wouldn't benefit from running on ...
0
votes
1
answer
139
views
Python's threading.enumerate function returns an unexpected results
I am using multithreading to run multiple Selenium drivers at the same time. Every driver has an individual thread. When I have 70 driver instances (ThreadPoolExecutor(max_workers=70)) len(threading....
0
votes
1
answer
260
views
Deadlock in Python garbage collection on exception
I have encountered a strange situation where a program won't exit due to the way python handles exceptions. In this situation, I have an object which owns a Thread, and this Thread is only shut down ...
0
votes
0
answers
46
views
How to run 2 functions working with API in telegram bot?
I created bot. It can handle some commands in chat and for working this part of him I use
def runBot():
bot.polling(none_stop=True, interval=1, timeout=30, long_polling_timeout=65)
and there is ...
1
vote
0
answers
81
views
Why does my heap size and thread count increase in this recursive Python code?
I'm working on finding a memory leak in my application, and narrowed down suspicious activity to this (simplified) code:
import time
import threading
class Work:
def by_duration(self, seconds: ...