python-multithreading

combining python watchdog with multiprocessing or threading

梦想与她 提交于 2019-12-31 23:25:13
问题 I'm using Python's Watchdog to monitor a given directory for new files being created. When a file is created, some code runs that spawns a subprocess shell command to run different code to process this file. This should run for every new file that is created. I've tested this out when one file is created, and things work great, but am having trouble getting it working when multiple files are created, either at the same time, or one after another. My current problem is this... the processing

Cannot close multithreaded Tkinter app on X button

萝らか妹 提交于 2019-12-31 07:17:13
问题 My app has the following structure: import tkinter as tk from threading import Thread class MyWindow(tk.Frame): ... # constructor, methods etc. def main(): window = MyWindow() Thread(target=window.mainloop).start() ... # repeatedly draw stuff on the window, no event handling, no interaction main() The app runs perfectly, but if I press the X (close) button, it closes the window, but does not stop the process, and sometimes even throws a TclError . What is the right way to write an app like

Multiprocessing inside a child thread

独自空忆成欢 提交于 2019-12-31 02:57:13
问题 I was learning about multi-processing and multi-threading. From what I understand, threads run on the same core, so I was wondering if I create multiple processes inside a child thread will they be limited to that single core too? I'm using python, so this is a question about that specific language but I would like to know if it is the same thing with other languages? 回答1: I'm not a pyhton expert but I expect this is like in other languages, because it's an OS feature in general. Process A

Python Webdriver Multithread

社会主义新天地 提交于 2019-12-31 00:44:17
问题 I'm trying to spawn multiple webdriver instances with the code from: http://www.ibm.com/developerworks/aix/library/au-threadingpython/ import time import Queue import urllib2 import threading from selenium import webdriver from BeautifulSoup import BeautifulSoup hosts = ["http://yahoo.com", "http://google.com", "http://amazon.com", "http://ibm.com", "http://apple.com"] queue = Queue.Queue out_queue = Queue.Queue class Login_Driver(threading.Thread): def __init__(self, queue, out_queue, driver

Interrupting Python raw_input() in a child thread with ^C/KeyboardInterrupt

≯℡__Kan透↙ 提交于 2019-12-30 18:29:50
问题 In a multithreaded Python program, one thread sometimes asks for console input using the built-in raw_input(). I'd like to be able to be able to close the program while at a raw_input prompt by typing ^C at the shell (i.e., with a SIGINT signal). However, when the child thread is executing raw_input, typing ^C does nothing -- the KeyboardInterrupt is not raised until I hit return (leaving raw_input). For example, in the following program: import threading class T(threading.Thread): def run

When to use threading and how many threads to use

安稳与你 提交于 2019-12-30 13:01:25
问题 I have a project for work. We had written a module and there as a #TODO to implement threading to improve the module. I'm a fairly new python programmer and decided to take a whack at it. While learning and implementing the threading, I had the question similar to How many threads is too many? because we have a queue of about maybe 6 objects that need to be processed, so why make 6 threads (or any threads at all) to process objects in a list or queue when the processing time is negligible

How to speed up communication with subprocesses

时光总嘲笑我的痴心妄想 提交于 2019-12-30 04:29:26
问题 I am using Python 2 subprocess with threading threads to take standard input, process it with binaries A , B , and C and write modified data to standard output. This script (let's call it: A_to_C.py ) is very slow and I'd like to learn how to fix it. The general flow is as follows: A_process = subprocess.Popen(['A', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) produce_A_thread = threading.Thread(target=produceA, args=(sys.stdin, A_process.stdin)) B_process = subprocess.Popen(['B', '-'

How to speed up communication with subprocesses

三世轮回 提交于 2019-12-30 04:28:51
问题 I am using Python 2 subprocess with threading threads to take standard input, process it with binaries A , B , and C and write modified data to standard output. This script (let's call it: A_to_C.py ) is very slow and I'd like to learn how to fix it. The general flow is as follows: A_process = subprocess.Popen(['A', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) produce_A_thread = threading.Thread(target=produceA, args=(sys.stdin, A_process.stdin)) B_process = subprocess.Popen(['B', '-'

Is threading.local() a safe way to store variables for a single request in Google AppEngine?

不想你离开。 提交于 2019-12-30 03:13:28
问题 I have a google appengine app where I want to set a global variable for that request only. Can I do this? In request_vars.py # request_vars.py global_vars = threading.local() In another.py # another.py from request_vars import global_vars get_time(): return global_vars.time_start In main.py # main.py import another from request_vars import global_vars global_vars.time_start = datetime.datetime.now() time_start = another.get_time() Questions: Considering multithreading, concurrent requests,

How to run a function so it works also when other functions work?

寵の児 提交于 2019-12-29 09:27:08
问题 For ex:- Below I have four different functions and they do all different things on a particular domain. Now What I want is to run crawler to work behind these other functions work so my code will move faster. crawler(domain) f2() f3() f4() How can I? I have tried this:- th = threading.Thread(crawler) th.start() f2() f3() f4() th.join() Is this code can be considered efficient and effective? 来源: https://stackoverflow.com/questions/46642992/how-to-run-a-function-so-it-works-also-when-other