python-multithreading

Python Threading not processed parallel

本秂侑毒 提交于 2021-02-04 07:11:24
问题 I'm intermidiate bee for python and would like to run the same class instances of few in parallel mode for fetching data and decision making for financial market. To proceed my idea, I run the following code to see how python works, it seems it works one complete run of first class instance and after second class instances, I would like to run this parallely, how can I...? Below is the some sample code for testing.. import threading import time class thr(object): def __init__(self, name):

How to run a function concurrently with matplotlib animation?

别说谁变了你拦得住时间么 提交于 2021-01-29 05:29:13
问题 I am building a GUI that takes in sensor data from the raspberry pi and displays it onto a window via matplotlib animation. The code works fine, except when being run on raspberry pi, the matplotlib animation takes some time to execute, which momentarily blocks the sensor reading GetCPM that I'm interested in. How can I make both these programs run simultaneously without one clogging the other, I've tried the multiprocessing library, but I can't seem to get it to work. Note: The sensor data

How to use concurrent.futures in Python

我的未来我决定 提交于 2021-01-28 08:44:18
问题 Im struggling to get multithreading working in Python. I have i function which i want to execute on 5 threads based on a parameter. I also needs 2 parameters that are the same for every thread. This is what i have: from concurrent.futures import ThreadPoolExecutor def do_something_parallel(sameValue1, sameValue2, differentValue): print(str(sameValue1)) #same everytime print(str(sameValue2)) #same everytime print(str(differentValue)) #different main(): differentValues = ["1000ms", "100ms",

How to pass a boolean by reference across threads and modules

拈花ヽ惹草 提交于 2021-01-28 07:28:17
问题 I have a boolean that I want to pass to different threads that are executing methods from different modules. This boolean acts as a cancellation token so if set, the thread should exit. It seems to be passed by value since if I set it in another thread it doesn't change in the other threads. Thanks. import module2 from threading import Thread cancellationToken = False def main: thread2 = Thread(target = module2.method2, args (on_input, cancellationToken, )) thread2.start() ... thread2.join()

RuntimeError: threads can only be started once Python Tkinter webserver

雨燕双飞 提交于 2021-01-28 06:48:45
问题 I am trying to create a webserver in python which can be started and stopped using a tkinter GUI. In tkinter I have a button which will call start() and a button that will call stop(). Initially everything works fine, the server starts when I click the button and it also stops when I click the stop button. When I try to restart the server again using the start button, I get a runtime error RuntimeError: threads can only be started once I believe it has something to do with the fact that I

pyqtgraph ImageView Freezes when multithreaded

为君一笑 提交于 2021-01-28 04:09:45
问题 I have multiple cameras that are hooked up wirelessly via wifi and I'm trying to stream the data to a client, which displays the streams on a GUI. My issue is that the pyqtgraph ImageItems seem to stop repainting after about 30 seconds, or if I click out of the window, or if I adjust the controls on one of the images. After that, I can manage to get the images to repaint by resizing the window, but that's kind of tedious. I thought maybe pyqtgraph wasn't threadsafe, but I don't even know if I

Ttk Indeterminate progress bar on button press

孤街醉人 提交于 2021-01-07 02:39:46
问题 I am trying to create a progress bar that runs as long as my function is running to show the user that things are happening and not just frozen. My function (generate_reports) makes queries to the database and writes to CSV files. Here is an abstract version of my code: from tkinter import * from tkinter import ttk from billing import generate_reports class app: def __init__(self, root): self.mainframe = ttk.Frame(root, padding = '4 4 12 12') self.mainframe.grid(column = 0, row = 0, sticky =

Why is the python thread count 2 at the beginning?

拈花ヽ惹草 提交于 2020-12-30 09:41:26
问题 import threading print threading.activeCount() output: 2 When this code is saved into a file and run. How could it be 2 when it's the main thread? Does python run another thread by default in addition to the main thread when we run a foo.py file? 回答1: Psychic debugging: You're not running in a plain Python interpreter. The plain Python interpreter doesn't launch extra threads (unless you have a weird PYTHONSTARTUP file), but other interpreters would. For example: ipython launches an extra

Why is the python thread count 2 at the beginning?

别来无恙 提交于 2020-12-30 09:38:17
问题 import threading print threading.activeCount() output: 2 When this code is saved into a file and run. How could it be 2 when it's the main thread? Does python run another thread by default in addition to the main thread when we run a foo.py file? 回答1: Psychic debugging: You're not running in a plain Python interpreter. The plain Python interpreter doesn't launch extra threads (unless you have a weird PYTHONSTARTUP file), but other interpreters would. For example: ipython launches an extra

Threading Decorator [Python]

浪尽此生 提交于 2020-12-13 03:37:55
问题 i'm trying to create a simple program using python socket and threading library. I would like to automatize the following procedure using a decorator: t = threading.Thread(target=function, args=(arg1, arg2)) t.start() the program is structured using OOP so I defined a subclass inside the main one to contain all the decorators (I've read about this method in this article: https://medium.com/@vadimpushtaev/decorator-inside-python-class-1e74d23107f6). Therefore I have a situation like this: