Questions tagged [python-multithreading]

python-multithreading refers to how to divide work into multiple streams of execution in Python.

python-multithreading refers to how to divide work into multiple streams of execution within a single process in Python. Usually this refers to the threading module. It could also refer to concurrent.futures.ThreadPoolExecutor or the thread/_thread module.

More information:

3995 questions
1
vote
1 answer

How to do Thread Safe Dictionary Manipulation

how to manipulate dict with thread-safe, i want to store dict to 2 different queue with different dict value (1 before manipulation, 1 after manipulation) but turns out both of them store dict after manipulation. here's my code from threading import…
1
vote
1 answer

Avoid waiting for threads to finish in Python

I've wrote this script here to read data from a txt file and process it. But it seems that if I give it a big file and a high number of threads, the more it reads from the list, the slower the script gets. Is there a way to avoid waiting for all the…
CarefullyAdvanced
  • 437
  • 1
  • 4
  • 15
1
vote
1 answer

PyQt5, how to restart operations running through threads

So I have been trying to create a GUI which works on multiple threads to perform each operation. Each operation actually has loops running on it and so I decided to use threads to run each operation simultaneously. Here's some piece of code which…
Saurav Saha
  • 745
  • 1
  • 11
  • 30
1
vote
1 answer

Share resources between concurrent python processes / executors?

I have a simple program that processes things read in from a file. There are many things and processing is not very fast and requires a huge data structure for looking up and calculating, so running this takes a lot of time. This should be trivially…
1
vote
1 answer

Terminating main thread from child thread

I have a GUI thread and Main thread. After closing a window I have method called inside the GUI thread. I would like to propagate this to Main thread to end its work. Main thread is doing several steps, so I am able to set stop_event, but I do not…
JankaSvK
  • 51
  • 5
1
vote
0 answers

Python threading or multi-processing is slower than running same programme in many tabs at the same time

I'm working on a programme which processes a huge json file and does some analysis before inserting into db In the beginning, my prototype of the programme is divided the json file into n parts. Then they runs independently by script: python…
Louis Luk
  • 303
  • 2
  • 16
1
vote
1 answer

python multithreaded application hanging

I have written a program that I am using to benchmark a mongodb database performing under multithreaded bulk write conditions. The problem is that the program hangs and does not finish executing. I am quite sure that the problem is due to writing…
1
vote
1 answer

Python multiprocessing - Allocate a new function to a finished process?

I have a list of 800 image files that I would like to process in parallel. Assume I store their names in a list as such: lis_fnames = ['im1.jpg','im2.jpg',...'] Then I import the multiprocessing module and from that I import Pool. I am giving each…
1
vote
1 answer

queue.Queue() or multiprocessing.Queue() for threads within a Process

Say I have 3 Processes: In Process A, there is an infinite loop that does something with self.marker. But at the same time, self.marker also needs to be updated every 1 minute so a threading.Timer is implemented to do this. This Timer will be…
jgv115
  • 499
  • 5
  • 17
1
vote
0 answers

100% cpu usage on one core in raspberry pi

I am doing a robotic project on raspberry pi in which i need frame from a webcam, attached to raspberry pi, continuously so i am extracting frames from videocapture() in a separate thread than main program and saving the frames in a queue. The…
whoosis
  • 454
  • 7
  • 25
1
vote
1 answer

Saving and retrieving thread object/state python

I am using the python threading module for the first time and this is what I am trying to find out -- can we save and load state of python thread object in some database or file? Let's say I have the below piece of code in a program (this program…
yguw
  • 856
  • 6
  • 12
  • 32
1
vote
1 answer

Using Threading and Queue in infinite loop does not close threads

I'm struggling to have python periodically run some threaded function and close threads (or reuse the same threads without spawning new ones). When running the code below it spawns new threads every time the function is ran and eventually the…
IlirB
  • 1,410
  • 14
  • 19
1
vote
1 answer

RuntimeError: cannot set daemon status of active thread

I am trying to run some test in parallel upon on_message callback. When my on_message callback gets called, based on some message, I create a thread to run some test and set it as daemon thread. When I run, I get this run-time error. "cannot set…
1
vote
1 answer

How do I use threads on a generator (multiple threads per item) while keeping the order?

I have a code that is mimicking a REST API call (see below). For every key in the item of the generator, it needs to run a REST call. So in my example, a record could be {"a": 2, "b": 36, "c": 77} I need to run a REST call for every key (a, b, and…
hobbes3
  • 28,078
  • 24
  • 87
  • 116
1
vote
1 answer

Python 3, timeout a thread from another thread

Currently I have been ending loops() from within the thread. Nesting if statements into loops() ... but if there are a lot of loops and nested loops, the statements become very redundant and create clutter. Is there a way to run a timeout thread…
Rhys
  • 4,926
  • 14
  • 41
  • 64
1 2 3
99
100