4,119 questions
-1
votes
2
answers
204
views
Custom ThreadPool and Request Queue
I am currently working on implementing a toy store server using Python, employing socket connections and a custom thread pool for handling concurrent client requests. However, I'm facing some ...
1
vote
1
answer
61
views
Is it necessary to pass a shared variable explicitly to a threading function in Python using args in Threads()or directly access it?
Is it necessary to pass a shared variable explicitly to a threading function like i have shown below (First example ) in Python 3.10+
Os is Windows 10,Python interpreter is CPython
or
is it ok to ...
-1
votes
1
answer
26
views
ive tried to implement multiple clients through threads, i am able to connect multiple clients if they are local, but accepts only 1 external connect
the main premise of the problem is to build a first responders system of sorts, which pings location to a server when a collision occurs(collision is currently an event triggered when the key k is ...
1
vote
0
answers
42
views
Python subprocess stoud handling while other code is running
I want to build a python script that start a subprocess and launches a CLI command(the cli command can take hours to run), so I want the main python to continue, however deploy a watcher, that keeps ...
0
votes
1
answer
863
views
Telegram bot can't send a message from another thread, Request Timeout
I use async version of pyTelegramBotApi for a Telegram bot part. I use vk-api for a VK part (not sure if that matters).
I have a bot that monitors other social network (Vkontakte) and, on some ...
0
votes
0
answers
188
views
MultiThreading with python and and pandas
I would need advice how to use multithreading with python. I'm currently using the concurrent.futures librairy but the results i got seem to be slower than expected.
Here an example :
I need to ...
0
votes
0
answers
177
views
Multithreading or Async file handling with Python
i have created a script which catches files in a folder and does conversion operation (from word to pdf) and it creates folders based on their file names and places them in there. However, problem is ...
0
votes
1
answer
71
views
Python script doesn't continue execution after creating thread
i'm trying to write a socket-server program to send keyboard inputs from my PC to my Raspberry Pi, but when i create a new thread for a function, that has a while loop in it, the script execution does ...
1
vote
1
answer
570
views
Writing Performant Python Bloomberg SAPI code to get streaming data from //blp/mkdata
All,
I have been using blpapi with Python to query reference data (//blp/refdata) without issues and I've recently been using the streaming endpoint (//blp/mkdata); so my environment is set up (yes ...
0
votes
0
answers
84
views
Python threadpool io bound tasks
Assume following code :
import concurrent.futures
import time
import itertools
def task_function(task_id):
print(f"Task {task_id} started")
time.sleep(10) # Simulating some work
...
2
votes
1
answer
524
views
When does Python switch between Threads when using the threading module?
Here's how I understand it (please correct me if I'm wrong): Python switches between Threads in certain time intervals. Additionally when waiting for an I/O Operation Python releases the GIL so that ...
0
votes
1
answer
80
views
Threading is replaceable in Python?
I have done some reading on the topic and found that we can use threading if some problem is io-bounded but io is not very slow. But I couldn't understand why we still couldn't use asyncio? Since ...
0
votes
2
answers
9k
views
Whenever i use xxx.join() it never works
Whenever i use xxx.join() it never works, eitehr just stops and doesnt carry on the rest of the code or crashes my program. in this case crashing my program. i usually make do without it, but for my ...
0
votes
1
answer
873
views
How do i mock a function being called inside the run method of a python threading.Thread inherenting class from the main thread
i have a function in a my_fuction.py
def my_function():
# do something
print("doing something")
return True
i also have a a threading.Thread inhereting class called my_thread....
0
votes
0
answers
37
views
main thread continues to run even when command window closes
Edit: Actually, execution does end eventually. However, there is a 6 second delay or so between when the window closes and when code execution actually terminates, a gap that is not present when the ...
0
votes
0
answers
71
views
Python OpenCV threading with tkinter
I have a small python opencv code to predict age and gender. I also have a GUI tkinter library to print the age on a separate window.
import cv2
import math
import time
import argparse
import requests
...
0
votes
1
answer
1k
views
Calling future.result() multiple times
I'm using Python's ThreadPoolExecutor to execute a function concurrently on different threads. The executed function returns an enum PytestResult and afterwards I'm logging the returned result and ...
0
votes
0
answers
108
views
Generating and playing audio whilst being connected to bluetooth device
I'm trying to write a script that plays pure tones (fixed frequency sine waves), whilst connected to a bluetooth device. I'm using bleak and asyncio to connect to the bluetooth sensor, and want the ...
0
votes
1
answer
177
views
Is there a way to block on applying tasks in Python ThreadPool if all the threads in the pool are busy?
I'm consuming a queue and need to pass the data to a thread pool for processing, but I don't want to consume more items than the thread pool can handle. In other words, I want the thread pool to ...
1
vote
1
answer
1k
views
RuntimeError: can't create new thread at interpreter shutdown while it works perfectly fine on another computer
I have a python program that I run in VSCode but at one point I'm getting this RuntimeError: can't create new thread at interpreter shutdown and I'm not even closing anything, I don't understand. And ...
1
vote
1
answer
176
views
Is it safe for one thread to write and one thread to read from the same file?
I need a Python script where a background thread writes data to a file, while the main thread might read from it.
I know writting to a file from multiple thread can be problematic, but is it OK if ...
1
vote
1
answer
124
views
Non-blocking thread pool that posts results as soon as they're ready for the main thread to access
import multiprocessing as mp
pool = mp.Pool()
def calc(i):
return i * 2
def done(results):
for result in results:
print(result)
def loop():
pool.map_async(calc, [0, 1, 2, 3], ...
0
votes
0
answers
36
views
written a thread unsafe code but acting as thread safe why?
i watched this video and written this code in python https://www.youtube.com/watch?v=oYoVx8ZuvTw
but my code is acting as thread safe why
please see video to understand my query
import threading
...
0
votes
1
answer
68
views
How do I disable the keyboard after a time?
I want that, while the program is running, all the keys I type are ignored. In a simple example, the problem I want to solve is the following.
from time import sleep
sleep(5)
If I type something ...
1
vote
1
answer
359
views
How to open a session and run each request on its own thread?
I am trying to connect to a server and download all the attachments from said server. I have these 2 functions. download_File() simply downloads the file from the server.
downloadFiles()
1. connects ...
0
votes
1
answer
248
views
Python ib-insync error - "There is no current event loop in thread 'Thread-6(--)'"
I created a thread in the main code. Inside the thread I call a procedure outside the thread. The called procedure runs fine except a line that's supposed to run an ib order, which throws the error &...
0
votes
1
answer
81
views
Cannot get this timer to restart
I'm building a bot that takes sound from a game, cross refrences it with a target sound, and if a target sound is detected does some actions.
I have a timer that runs from the time I press "start&...
0
votes
1
answer
310
views
Why using while control instead of if control in condition variables to synchronize different threads?
I have simple producer, consumer problem. While producer thread adding 10$ to global money variable, consumer thread will spend money. But there is one condition that money cannot be under 0. The ...
0
votes
1
answer
194
views
WebSockets query fails with short heartbeat
I have a Python server which serves some long-running queries for large amounts of data from a Postgres DB. The requests are served via WebSockets, and the server uses asyncio and aiohttp as the main ...
1
vote
0
answers
208
views
Polling in py-spy flame graph of celery worker
I am debugging a celery worker running in a docker container.
Celery version: 5.2.7
broker: rabbitmq
results backend: redis
profiling: py-spy 0.3.14
docker: 24.0.7
I launch the celery worker with:
...
1
vote
1
answer
2k
views
How to run a Dash app with threading and with debug=True?
This demo app runs a python process with a Plotly / Dash user interface. When it starts Dash with app.run_server(debug=True) the following error is raised:
Exception in thread Thread-1 (dashfun):
...
0
votes
1
answer
68
views
Can't stop socket server thread from within
I have the following situation:
I have a class called Server, which is, as the name tells, the class which starts the server and is supposed to stop it. Here's the code:
import socket
import threading
...
1
vote
1
answer
254
views
What does the term Synchronization primitive mean in python threading?
The term Synchronization primitive is used in many places in the documentation of threading. I have referenced one such usage in the description of RLock:
A reentrant lock is a synchronization ...
0
votes
0
answers
245
views
Python ThreadPoolExecutor: dynamically control the amount of available workers
I'm writing a script that does the following:
Gets the number of available VMs and put them in a stack
Discover tests files and put them in a queue
Runs the tests concurrently on each VM
To achieve ...
0
votes
0
answers
79
views
Dynamic allocation of CPUs to threads with multithreading at runtime
The general use case:
I want to parallelize the executions of a Python script with multiple inputs. The inputs are wordlists (.txt files) of different sizes (from 2.000 to 3.000.000 rows).
The setup:
...
0
votes
0
answers
51
views
Cant make sure only one thread is talking to a device - Python
Ive got three threads.
One for getting Data from a device.
One for calculation something
and the last is a tkinter thread.
Everytime one of these threads has an error a Device needs to be resetted. ...
3
votes
0
answers
96
views
time.sleep(0) on Windows vs Unix [duplicate]
The Python documentation states that
On Windows, if secs is zero, the thread relinquishes the remainder of
its time slice to any other thread that is ready to run. If there are
no other threads ready ...
0
votes
1
answer
672
views
threaded python-can suddenly stops sending messages
I have a strange issue with my canbus thread, maybe somebody here is able to help.
I set up a test environment with the class below and another file thats just simulating the other can module via ...
0
votes
1
answer
70
views
how to kill winsound task after an if condition
I have a code that will play an alarm then when I press h it should stop working here's the code:
import winsound
from threading import Thread
import keyboard
import sys
alarm_flag = True
def alarm():
...
-2
votes
1
answer
61
views
Python - How to use the function's old result while waiting for its new result
Let's say I have 2 functions like this:
Function 1: To Calculate a. And it takes 5 hours to return the result of a for each calculation.
def Calculate_a (x,y,z,t)
Do_somthing_to_calculate_a
...
0
votes
0
answers
43
views
How to implement a parallel task queue with returning result?
I have a webserver with incoming requests for data processing.
The processing must be performed by a stateful worker (e.g. an exclusive database connection), but an arbitrary number of workers can run ...
0
votes
1
answer
47
views
unexpected behavior of for after using Map and Partial method
I'm using Partial method to pass 2 parameters which are not iterables, thus i shouldn't use that in the Map() function. I'm also using ThreadPoolExecutor for I\O bound task that i have here.
the ...
0
votes
1
answer
74
views
Quit Tkinter application by calling class method
I am trying to build a splash screen that I will be able to call from an external application using Tkinter. I'd like to define my GUI in a class, like this:
class Splash:
def __init__(self):
...
0
votes
0
answers
50
views
Best way to run several heavy processes in python
I have an indeterminate number of csv files. I want to back them up, then process them and save the result in the same file. The process is kind of heavy and it involves manipulating the values in the ...
0
votes
1
answer
269
views
QT5, Threading, Sockets : Issue with GUI and QRunnable in Python
I'm looking for help for my project with threading and sockets. I have to make a communication between a server and few clients, and I have to do a GUI.
The issue is that when I use QRunnable, the GUI ...
0
votes
1
answer
167
views
Issues with catching exceptions in a ThreadPoolExecutor
I have written the following class:
class AsyncPillow:
def __init__(self, FUNC: Callable, ARGS: tuple, POOL: ThreadPoolExecutor = None):
self.FUNC = FUNC
self.ARGS = ARGS
...
0
votes
1
answer
74
views
Django model.save() doing inconsistent updates
I am using django ORM to communicate with MySQL database inside the callback functions of my RabbitMQ consumers. These consumers are running on a separate threads and each consumer has established its ...
0
votes
0
answers
318
views
Application randomly crashes when setting QProgressbar from another thread [duplicate]
I am writing a part of a basic FFmpeg GUI application, and this is the installation code.
While setting install_progress_bar from the 'download_thread' the terminal is spammed with QObject::setParent: ...
0
votes
0
answers
381
views
Python. pymssql.fetchall() performance slows down when using Thread, threading
I have a problem that I just can't solve on my own.
There is a Python script that looks something like:
from threading import Thread
import threading
import pymssql
lock = threading.Lock()
global_list ...
0
votes
1
answer
157
views
Setting a watch function using kazoo when calling Zookeeper from a Flask application deployed using gunicorn
I have a Flask application deployed using gunicorn. I'd like to integrate the application with a Zookeeper ensemble using kazoo, as the app relies on having up to date data from a get_children() call ...