python-multithreading

Multiprocessing backed parallel loops cannot be nested below threads

僤鯓⒐⒋嵵緔 提交于 2019-12-28 16:51:54
问题 What is the reason of such issue in joblib? 'Multiprocessing backed parallel loops cannot be nested below threads, setting n_jobs=1' What should I do to avoid such issue? Actually I need to implement XMLRPC server which run heavy computation in background thread and report current progress through polling from UI client. It uses scikit-learn which are based on joblib. P.S.: I've simply changed name of the thread to "MainThread" to avoid such warning and everything looks working good (run in

Return value from thread

柔情痞子 提交于 2019-12-28 01:51:08
问题 How do I get a thread to return a tuple or any value of my choice back to the parent in Python? 回答1: I suggest you instantiate a Queue.Queue before starting the thread, and pass it as one of the thread's args: before the thread finishes, it .put s the result on the queue it received as an argument. The parent can .get or .get_nowait it at will. Queues are generally the best way to arrange thread synchronization and communication in Python: they're intrinsically thread-safe, message-passing

A very simple multithreading parallel URL fetching (without queue)

倖福魔咒の 提交于 2019-12-27 11:52:28
问题 I spent a whole day looking for the simplest possible multithreaded URL fetcher in Python, but most scripts I found are using queues or multiprocessing or complex libraries. Finally I wrote one myself, which I am reporting as an answer. Please feel free to suggest any improvement. I guess other people might have been looking for something similar. 回答1: Simplifying your original version as far as possible: import threading import urllib2 import time start = time.time() urls = ["http://www

Asyncore client in thread makes the whole program crash when sending data immediately

扶醉桌前 提交于 2019-12-25 17:42:36
问题 I write a simple program in python, with asyncore and threading. I want to implement a asynchorous client without blocking anything, like this: How to handle asyncore within a class in python, without blocking anything? Here is my code: import socket, threading, time, asyncore class Client(asyncore.dispatcher): def __init__(self, host, port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((host, port)) mysocket = Client("",8888)

Threading.Timer(5, function) launch every 5 second

天涯浪子 提交于 2019-12-25 08:49:45
问题 I'm having a hard hard time with Timer function from threading. Basically, when my program starts, I want to log stats every x second. So I thought I could do it with the Timer function (launch function every 5 second). For now, I did : from threading import Timer def startLogger(): while True: t = Timer(5, function) t.start() def function(): print("hey") But it launch error, so I think it's not the good way to do it. RuntimeError: can't start new thread If someone can give me a clue, it

Multichannel sound syncronization issues in Python (Sounddevice)

爷,独闯天下 提交于 2019-12-25 08:13:58
问题 I am currently working on a script that should be able to output 8 channels of audio (.wav files) to 8 different channels on a soundcard. My script is sort of working, but I have syncronization issues. I am able to hear that the timing between the channels changes during playback, which is very critical. Currently I am using threads to start each channel of sound. My question is, if you guys have any suggestions to how I can achieve a better synchronization between channels/threads? I would

Multichannel sound syncronization issues in Python (Sounddevice)

本秂侑毒 提交于 2019-12-25 08:10:13
问题 I am currently working on a script that should be able to output 8 channels of audio (.wav files) to 8 different channels on a soundcard. My script is sort of working, but I have syncronization issues. I am able to hear that the timing between the channels changes during playback, which is very critical. Currently I am using threads to start each channel of sound. My question is, if you guys have any suggestions to how I can achieve a better synchronization between channels/threads? I would

Tkinter.Tk() and threading

核能气质少年 提交于 2019-12-25 06:26:56
问题 There is an interesting issue with Tkinter and threading: I have a Tkinter based GUI and some code executed alongside mainloop. It works like charm if I only do it once. But if i do it twice Tkinter.Tk() blocks BOTH threads: GUI and MainThread. here is the code (inspired by another Tkinter vs threading topic): import Tkinter import threading import logging logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s: %(message)s") def gui(): logging.info("Starting GUI") root =

Closing a Toplevel() window from a seperate thread using Threading

元气小坏坏 提交于 2019-12-25 02:55:13
问题 My Program uses VLC bindings to play a video while using the time.sleep function to wait until the video is over before playing the next video. It will play in a loop until the user presses a button and will only exit after that video is completed. I am using Threading to handle the video playing as the time.sleep takes control away from the root window and the buttons are required to stop the video. Threading solves this. My only problem is that the video needs to embed in a window. This

Python: threading + curve_fit: null argument to internal routine

爷,独闯天下 提交于 2019-12-25 02:18:22
问题 I have got some problems using the following code, which is supposed to do gaussian fits using threads: from PIL import Image import numpy as np from scipy.optimize import curve_fit import threading class myThread (threading.Thread): def __init__(self, index): threading.Thread.__init__(self) self.index = index def run(self): for i in np.arange(n_Bild.shape[1]): curve_fit(self.gauss, x_x, Intensitaet[self.index, ...], p0=(Intensitaet[self.index, i], i, 1, 0)) def gauss(self, x, a, b, c, d):