4,120 questions
Advice
0
votes
6
replies
98
views
Optimizing sys.stdout.write()
I am an amateur playing around with making simple games using Python and the Windows console through sys.stdout.write(). I am aware that this method of doing 'graphics' with printing ascii characters ...
0
votes
2
answers
83
views
threading.Thread cannot catch a PyCharm "stop" button termination event
I am using Pycharm. When I click the "stop" button, the subprocess.Popen deletes the left over .bat files. But after putting the subprocess.Popen inside a threading.Thread function, the .bat ...
4
votes
1
answer
124
views
Python tkinter not executing button commands on Raspberry Pi
I am developing an app to select and play a mp3 clip from a list. It will be run on a Pi4 with 7” touch display and piAMP+ hat. The GUI is in tkinter with pygame for the sound plus a pair of GPIO pins ...
3
votes
1
answer
278
views
Python 3.14 removes GIL. What possibilities of data races can happen in Python now? And how to handle them? [closed]
Are python references atomic under concurrent access? Are dictionaries and lists thread-safe?
-1
votes
1
answer
89
views
Closing QDialog internally
I am trying to start a Dialog including QListWidget. In this list every time a status is changed, the list should get a new line. At the end, if the backup process has finished, the dialog should ...
2
votes
1
answer
66
views
Cannot start a ThreadPoolExecutor inside a threading.Thread function
In this example, Tkinter GUI starts ThreadPoolExecutor. But ThreadPoolExecutor is inside a threading.Thread function. The thread function says it's finished
before ThreadPoolExecutor has started ... ...
0
votes
0
answers
49
views
OSX does not display the names of free-threaded python threads [duplicate]
I am running free-threaded python3.13t with PYTHON_GIL=0 on MacOS Sequoia 15.7.
I create threads like this:
thread = threading.Thread(target=lambda: time.sleep(10), name="test-thread")
...
2
votes
1
answer
125
views
Threading or asyncio for serial communications?
I'm running some serial commands to test connected devices under test (DUTs), & we have a need to run these in parallel/concurrently to speed up our tests. I would like some feedback on which ...
-1
votes
2
answers
133
views
ThreadPoolExecutor is running the functions in sequence, not in parallel [duplicate]
We run a bunch of wireless controllers (mc's) and I want to use the controller API to transfer firmware via TFTP to each controller in preparation for an upgrade (the API call needs to be run on each ...
2
votes
1
answer
2k
views
import sentence_transformers hangs on macOS with [mutex.cc] RAW: Lock blocking error
I'm encountering a persistent issue where importing the sentence_transformers library on macOS causes my Python script to hang indefinitely. When the script hangs, the only output I see is a low-level ...
0
votes
1
answer
43
views
Socketio background task issues with pubsub subscription
I am running a gunicorn server with 1 eventlet worker through which I communicate with the FE via websockets.
However, I also need to listen to an external pod running some code that will emit a redis ...
0
votes
1
answer
94
views
How to cancel an await asyncio.StreamReader.readline() call?
I am using asyncio.StreamReader to continuously process line based communication like this:
reader, writer = await asyncio.open_connection(host, port)
while running:
line = await reader.readline()
...
-1
votes
3
answers
80
views
How to run a function while listening to a port
I am running a script that listens for webhook on my local machine using the following pattern :
from flask import Flask, request, abort
app = Flask(__name__)
@app.route("/", methods=["...
0
votes
2
answers
62
views
Python threads killed when main thread times out with only one thread, but survive when more than one threads are created
I have a Python function decorated with a 1-minute timeout. Inside it I spawn one or more worker threads that each run a 2-minute sleep via a dynamically executed script (using exec() in a custom ...
8
votes
2
answers
542
views
What happens to the asyncio event loop when multiple CPU-bound tasks run concurrently in a ThreadPoolExecutor given Python’s GIL?
I'm working on an asynchronous Python application (using FastAPI/Starlette/asyncio) that needs to offload synchronous, CPU-bound tasks to a thread pool (ThreadPoolExecutor) to avoid blocking the event ...
2
votes
1
answer
89
views
Python Threading + Tkinter: Event.set() doesn't terminate thread if bound to Tk window closing
I'm writing an app that generates a live histogram to be displayed in a Tkinter window. This is more or less how the app works:
A Histogram class is responsible for generating the embedded histogram ...
0
votes
3
answers
92
views
Thread tkinter does not terminate
Yet another question about tkinter terminating...
Here is a minimal code :
import threading,tkinter,random
class MiniTk :
done = lambda self : self._quit.is_set()
spot = lambda self,x,y : ...
1
vote
1
answer
85
views
Python script locked by thread
I would like this Python 3.10 script (where the pynput code is partially based on this answer) to enter the while loop and at the same time monitor the keys pressed on the keyboard. When q is pressed, ...
0
votes
1
answer
82
views
Thread leakage issues during code testing
When performing OCR on user-selected regions using PaddleOCR, certain regions fail to be detected. The issue occurs in a Streamlit-based application with the following implementation characteristics:
...
2
votes
1
answer
67
views
Why does tqdm mess up cProfile output?
When profiling some Python code, I've been frustrated by functions like threading.py:637(wait) appearing high in cProfile output instead of the hot functions I want to see. After some tests I realized ...
0
votes
0
answers
54
views
How to exit a Python Win32 GUI program on Ctrl-C from invoking console
I have a simple Python Win32 program that works well when run under pythonw from a command prompt. When I run it under python, it keeps running in the foreground of the command prompt and can e.g. ...
0
votes
0
answers
62
views
Unpredictable behaviour when reading from stdin in python daemon thread
The python documentation says of daemon threads:
A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left.
...
0
votes
0
answers
53
views
Launch only one background task with multiple Gunicorn workers
I have a flask application that I run with Gunicorn.
The application itself would ideally be run with multiple workers. I also have some data I need to consume from Kafka, but that should only be one ...
0
votes
0
answers
39
views
The set_result() of Future doesn't end the await after the loop of create_task()
I write a Python program involving a loop of create_task() that calls async functions. In each task, it waits for another thread to set the result for a Future object.
async def run(self) -> int:
...
0
votes
0
answers
21
views
Is there a way to interrupt speech in pyttsx3?
I've tried emptying the queue every time. I've tried self.engine.stop. It either doesn't affect anything or it will work and successfully interrupt the previous speech one, twice or maybe even thrice ...
0
votes
0
answers
20
views
PySimpleGUI - working of two windows at the same time [duplicate]
I have a project using the PySimpleGUI library. The application has many windows. The project is built as follows:
def window_nr_2():
layout2 = [[sg.Button ('But A'), sg.Button ('But B')]]
...
-1
votes
1
answer
66
views
Background threads stoping
i have a python application, that contains functions to be called by interval.
def call_repeatedly(interval, func, *args, **kwargs):
stopped = threading.Event()
lock = threading.Lock() # Lock ...
0
votes
2
answers
89
views
How do I preserve and reconcile mutable object state across parallel tasks, when pickling breaks references in Python multiprocessing?
We're working on a concurrency problem where a single "Sample" object has multiple dependent tasks that must be executed in stages. For instance, stage 1 has tasks (1a, 1b), stage 2 has ...
0
votes
0
answers
411
views
How to read data from Siemens S7-1500 PLC asynchronously using Python and snap7?
I am trying to read data from a Siemens S7-1500 PLC in an asynchronous way using Python and the snap7 library. My goal is to read multiple tags concurrently. However, I am encountering the error b'CLI ...
0
votes
1
answer
45
views
Stop thread flow (audio) by condition in Python
There are streams: music - plays music, run - asks to enter something. I want that if "r" is entered, the music stream is interrupted by this condition. I understand that the flag with the ...
0
votes
1
answer
85
views
PyQT manual animation of Mouse Cursor. Repeatedly change shapes needed for cursor. Works on main thread. Doesnt work on separate thread. How so?
I would like to implement changing cursor in PyQT(PySide6) application. Since didn't find animated gif support for QCursor -> decided to create my own manual animation.
So far:
When change cursor ...
2
votes
1
answer
136
views
Multiprocessing with tkinter progress bar, minimal example
I'm looking for a way to track a multiprocessing task with Tkinter progress bar. This is something that can be done very straightforwardly with tqdm for display in the terminal.
Instead of using tqdm ...
0
votes
1
answer
117
views
Initializing Hugging Face Transformer restarts program loop
Initializing hugging face transformer causes loops to restart. I have created simple loop which reads text and replies but the loop is restarting new thread when initalizing chatbot pipeline. Minimum ...
0
votes
1
answer
48
views
Can I do multiple processes using Threading in python to achieve a "Idle game" kind of code?
I want to create an idle game, but I can't figure out how to get the system of "Money per second" to work.
The idea is to have a main function that takes input from the user and another ...
0
votes
0
answers
72
views
Interface between threaded and asynchronous parts of an application in Python
I'm helping develop a Python application which collects data from several sensors and manages a server to send those data to a web application (React) to display. The application is supposed to work ...
0
votes
1
answer
133
views
How do I update a matplotlib plot in realtime and also have a REPL?
I am in a situation where I have a primitive REPL with some simple commands. These commands generate data and put the data into a threadsafe queue. I then have a function that takes the data from the ...
2
votes
1
answer
129
views
Thread-insafe examples are behaving in a thread-safe way, is their a reliable way to demonstrate the problems that Locks resolve?
I am trying to create small examples using Locks to demonstrate the issues that Locks will resolve in a multi-threaded environment.
The example I created is the following,
import threading
# Shared ...
0
votes
1
answer
153
views
NotImplementedError when using threading with a keyboard and mouse listener with pynput
Here is the keyboard and mouse listener part of my code:
python
def mouse_listener(scroller):
"""Listens for mouse scroll events to scroll clipboard history."""
...
0
votes
0
answers
29
views
python3 multi threading with sqlite shared memory error in wal mode: sqlite3.OperationalError: database table is locked
I am trying to implement the shared memory database. The objective is to allow non-blocking reading access to the database for the IPC among threading.
The setting is following
def __init__(self):
...
1
vote
1
answer
107
views
How does Python ThreadPoolExecutor switch between concurrent threads?
How does Python ThreadPoolExecutor switch between concurrent threads?
In the case of the async/awaint event-loop, the switching between different pieces of the code happens at the await calls. Does ...
0
votes
2
answers
482
views
How to clean up thread-local data after using ThreadPoolExecutor?
I want to use ThreadPoolExecutor to parallelize some (legacy) code with database access. I would like to avoid creating a new database connection for each thread, so I use threading.local() to keep a ...
0
votes
0
answers
427
views
await asyncio.to_thread blocks complete event loop?
I am trying to create a Python program that - when triggered via a websocket - does some blocking work in a thread. I would expect my program to be able to continue to react to the stop signal also ...
1
vote
2
answers
43
views
Multiprocessing value() ctypes.c_wchar_p cause thread to stuck, alternative?
I'm doing concurrency using Multiprocessing() and Threading(). The idea is to spawn multiple threads from multiple process. The threads needs to access global variable that use Value() so that ...
0
votes
1
answer
79
views
KeyboardInterrupt doesn't work as expected
Ask please why press Ctrl + C ( KeyboardInterrupt) does not work as expected. (the process is not interrupted, continues to work)
from concurrent.futures import ThreadPoolExecutor
def sleeper(n):
...
0
votes
0
answers
38
views
Flask App Randomly Restarting When Running with Apache and mod_wsgi
I'm having an issue with a Flask application that I'm running using Apache and WSGI on a Raspberry Pi. The application restarts intermittently, and it seems that Apache is restarting the application ...
0
votes
3
answers
50
views
How to stop 2 threads in 1 function
I have some program that communicates with the user. The program should terminate when the user has entered a sample text.
import time
import threading
def printer():
while True:
print(&...
1
vote
0
answers
43
views
How can I make a google drive token refresh itself with a pyautogui function in python
I'm building a program that upload regurlarly videos on a google drive where I use them.
The thing is, I have to refresh often the tokens by manually clicking and I don't want that.
I built a function ...
1
vote
1
answer
180
views
Is a lock recommended in python when updating a bool in one direction in a thread, then reading it in another?
Is a lock necessary in a situation where thread 1 checks if a bool has flipped from False to True periodically within a loop, the bool being updated in thread 2?
As I understand a bool is atomic in ...
-1
votes
2
answers
118
views
Why is multi processing taking longer than single processor on Windows and Mac?
From what i know if u divide a large task into multiple processes the time taken to complete the task reduces but this is not happening in my code.
from multiprocessing import Process
import time
...
-1
votes
1
answer
39
views
pygame multiplayer jsondecodeerror
I'm developing a two-player multiplayer game with pygame.
Here is the server code and client code:
<Server Code>
import json
import pygame # Main module for the game
import pyautogui # For ...