python-multithreading

Python Webdriver Multithread

倖福魔咒の 提交于 2019-12-01 19:10:55
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): threading.Thread.__init__(self) self.queue = queue self.out_queue = out_queue self.driver = driver

“Can't start a new thread error” in Python

こ雲淡風輕ζ 提交于 2019-12-01 18:43:25
问题 I am running a script which extracts the information from debian packages and saves it in a database. After extracting information from about 100 packages an error occurs. The error is "can't start a new thread" Why am I facing this error? What can be the possible solution to it? This is the code used to save the data : for i in list_pack: if not i in oblist: #Creating Packages slu=slugify(i) ob=Gbobject() ob.title=i ob.slug=slu ob.content='' ob.tags=tagname #with reversion.create_revision():

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

陌路散爱 提交于 2019-12-01 17:07:34
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(self): x = raw_input() print x if __name__ == '__main__': t = T() t.start() t.join() Typing ^C does

How to process a list in parallel in Python? [duplicate]

不问归期 提交于 2019-12-01 11:28:05
This question already has an answer here: Is there a simple process-based parallel map for python? 4 answers I wrote code like this: def process(data): #create file using data all = ["data1", "data2", "data3"] I want to execute process function on my all list in parallel, because they are creating small files so I am not concerned about disk write but the processing takes long, so I want to use all of my cores. How can I do this using default modules in python 2.7? You may try a basic example like: from threading import Thread def process(data): print "processing %s" % data all = ["data1",

How to process a list in parallel in Python? [duplicate]

本小妞迷上赌 提交于 2019-12-01 08:56:28
问题 This question already has answers here : Is there a simple process-based parallel map for python? (4 answers) Closed last year . I wrote code like this: def process(data): #create file using data all = ["data1", "data2", "data3"] I want to execute process function on my all list in parallel, because they are creating small files so I am not concerned about disk write but the processing takes long, so I want to use all of my cores. How can I do this using default modules in python 2.7? 回答1:

Python multiprocessing BETWEEN Amazon cloud instances

孤街浪徒 提交于 2019-12-01 06:44:15
I'm looking to run a long-running python analysis process on a few Amazon EC2 instances. The code already runs using the python multiprocessing module and can take advantage of all cores on a single machine. The analysis is completely parellel and each instance does not need to communicate with any of the others. All of the work is "file-based" and each process works on each file indivually ... so I was planning on just mounting the same S3 volume across all of the nodes. I was wondering if anyone knew of any tutorials (or had any suggestions) for setting up the multiprocessing environment so

Why is my Python app stalled with 'system' / kernel CPU time

天涯浪子 提交于 2019-12-01 05:16:24
First off I wasn't sure if I should post this as a Ubuntu question or here. But I'm guessing it's more of an Python question than a OS one. My Python application is running on top of Ubuntu on a 64 core AMD server. It pulls images from 5 GigE cameras over the network by calling out to a .so through ctypes and then processes them. I am seeing frequent pauses in my application causing frames from the cameras to be dropped by the external camera library. To debug this I've used the popular psutil Python package with which I log out CPU stats every 0.2 seconds in a separate thread. I sleep for 0.2

Using Flask-Mail asynchronously results in “RuntimeError: working outside of application context”

我与影子孤独终老i 提交于 2019-12-01 03:10:16
问题 I am trying to send some mail asynchronously (based on the code in The Flask Mega-Tutorial, Part XI: Email Support). However, I get the following error about working outside an application context. How do I fix this problem? Traceback (most recent call last): File "C:\Users\Primoz\Desktop\RecycleFlaskServer\recycleserver\helpers.py", line 17, in send_async_email mail.send(msg) File "C:\Python33\lib\site-packages\flask_mail-0.9.0-py3.3.egg\flask_mail.py", line 434, in send message.send

Thread and asyncio: Task was destroyed but it is pending

倖福魔咒の 提交于 2019-11-30 20:05:45
问题 I have a thread that runs an asyncio loop. I start a future task that does things which are irrelevant here. When I stop the thread, I stop the asyncio loop as well. However, I cannot seem to cancel the pool task and get Task was destroyed but it is pending! Here is a toy example: from contextlib import suppress from threading import Thread from time import sleep import asyncio class Hardware(Thread): def __init__(self, *args, **kwargs): super(Hardware, self).__init__(*args, **kwargs) self

Python threading error - must be an iterable, not int

◇◆丶佛笑我妖孽 提交于 2019-11-30 18:27:53
问题 I'm trying to calculate rolling r-squared of regression among first column and other columns in a dataframe (first column and second, first column and third etc.) But when I try threading, it kept telling me the error that TypeError: ParallelRegression() argument after * must be an iterable, not int". I'm wondering how do I fix this? Thanks very much! import threading totalThreads=3 #three different colors def ParallelRegression(threadnum): for i in range(threadnum): res[:,i]=sm.OLS(df.iloc[: