python-multithreading

What is the best way to stop a thread and avoid 'RuntimeError' in python using threading and tkinter modules?

泪湿孤枕 提交于 2020-06-27 08:16:20
问题 I have went through multiple solutions on the net, but they require a lot of code that might get confusing once you scale up. Is there a simple way to stop the thread and avoid the RuntimeError: threads can only be started once , in order to call the thread an infinite number of times. Here is a simple version of my code: import tkinter import time import threading def func(): entry.config(state='disabled') label.configure(text="Standby for seconds") time.sleep(3) sum = 0 for i in range(int

Restarting a thread in Python

99封情书 提交于 2020-06-22 09:55:26
问题 I'm trying to make threaded flight software for a project in Python 3.4, in which I need threads to restart themselves in case an I/O error occurs during a sensor read or another fluke crash like that. Therefore I am working on making a watchdog to check if threads have died and restarting them. At first I attempted to just check if the thread was no longer alive and restart it, which did this: >>> if not a_thread.isAlive(): ... a_thread.start() Traceback (most recent call last): File "<stdin

Restarting a thread in Python

笑着哭i 提交于 2020-06-22 09:55:05
问题 I'm trying to make threaded flight software for a project in Python 3.4, in which I need threads to restart themselves in case an I/O error occurs during a sensor read or another fluke crash like that. Therefore I am working on making a watchdog to check if threads have died and restarting them. At first I attempted to just check if the thread was no longer alive and restart it, which did this: >>> if not a_thread.isAlive(): ... a_thread.start() Traceback (most recent call last): File "<stdin

How to deal with python3 multiprocessing in __main__.py

☆樱花仙子☆ 提交于 2020-06-16 04:17:56
问题 Il posed question, I did not understand the ture cause of the issue (it seems to have been related to my usage of flask in one of the subprocesses). PLEASE IGNORE THIS (can't delete due to bounty) Essentially, I have to start some Processes and or a pool when running a python library as a module. However, since __name__ == '__main__' is always true in __main__.py this proves to be an issue (see multiprocessing docs: https://docs.python.org/3/library/multiprocessing.html) I've attempted

tkinter updating progress bar on thread progress

若如初见. 提交于 2020-05-29 09:58:22
问题 from tkinter import * from tkinter.ttk import * import threading import numpy as np def bar(): #function to display progress pass with open('/home/user154/test.txt') as f: total=f.read().split('\n') root = Tk() links = list(filter(None, total)) #16530 links threads =[] #creating chunks of length 10 chunks = [i.tolist() for i in np.array_split(links, 10) if i.size>0] # Progress bar widget progress = Progressbar(root, orient = HORIZONTAL, length = len(links), mode = 'determinate') #launching

Can't pickle Pyparsing expression with setParseAction() method. Needed for multiprocessing

我的梦境 提交于 2020-05-29 09:44:53
问题 My original issue is that I am trying to do the following: def submit_decoder_process(decoder, input_line): decoder.process_line(input_line) return decoder self.pool = Pool(processes=num_of_processes) self.pool.apply_async(submit_decoder_process, [decoder, input_line]).get() decoder is a bit involved to describe here, but the important thing is that decoder is an object that is initialized with PyParsing expression that calls setParseAction(). This fails pickle that multiprocessing uses and

Multi-Threading in PyQt 5

孤街浪徒 提交于 2020-05-29 08:43:15
问题 I've been learning about multi-threading, specifically in the context of a PyQt 5 application. Initially I implemented a version using 'threading', but have since learnt that I should be using 'QThread' to allow use of signals / slots, e.g: workerThread = QThread() workerObject = Worker(cmdlist) workerObject.moveToThread(workerThread) workerThread.started.connect(workerObject.run) workerObject.finished.connect(workerThread.quit) However, is it possible to design a system in which: Each class

How does ThreadPoolExecutor().map differ from ThreadPoolExecutor().submit?

老子叫甜甜 提交于 2020-05-24 08:53:28
问题 I was just very confused by some code that I wrote. I was surprised to discover that: with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor: results = list(executor.map(f, iterable)) and with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor: results = list(map(lambda x: executor.submit(f, x), iterable)) produce different results. The first one produces a list of whatever type f returns, the second produces a list of concurrent.futures.Future objects that then

Reusing Tensorflow session in multiple threads causes crash

柔情痞子 提交于 2020-05-15 05:52:05
问题 Background: I have some complex reinforcement learning algorithm that I want to run in multiple threads. Problem When trying to call sess.run in a thread I get the following error message: RuntimeError: The Session graph is empty. Add operations to the graph before calling run(). Code reproducing the error: import tensorflow as tf import threading def thread_function(sess, i): inn = [1.3, 4.5] A = tf.placeholder(dtype=float, shape=(None), name="input") P = tf.Print(A, [A]) Q = tf.add(A, P)

Pandas, Concurrent.Futures and the GIL

懵懂的女人 提交于 2020-05-13 14:12:28
问题 I'm writing code using Pandas 0.18/Python 3.5 on an intel i3 (four cores). I have read this: https://www.continuum.io/content/pandas-releasing-gil I also have some work that is IO bound (parsing CSV files into dataframes). I have to do a lot of calculation that is mostly multiplying dataframes. My code is currently parallel using concurrent.futures ThreadPoolExecutor . My question is: In general, should I be using threads to run pandas jobs in parallel, or does pandas make effective use of