python-multithreading

Multi-threading in selenium python

为君一笑 提交于 2019-12-19 04:08:28
问题 I am working on a project which needs bit automation and web-scrapping for which I am using Selenium and BeautifulSoup (python2.7) . I want to open only one instance of a web browser and login to a website, keeping that session , I am trying to open new tabs which will be independently controlled by threads, each thread controlling a tab and performing their own task. How should I do it? An example code would be nice. Well here's my code: def threadFunc(driver, tabId): if tabId == 1: #open a

Understand python threading bug

烈酒焚心 提交于 2019-12-18 12:18:12
问题 Reading http://bugs.python.org/msg160297, I can see a simple script written by Stephen White which demonstrates how python threading bugs up with this exception Exception AttributeError: AttributeError("'_DummyThread' object has no attribute '_Thread__block'",) in <module 'threading' Given Stephen White's source code (http://bugs.python.org/file25511/bad-thread.py), import os import thread import threading import time def t(): threading.currentThread() # Populate threading._active with a

Process vs. Thread with regards to using Queue()/deque() and class variable for communication and “poison pill”

佐手、 提交于 2019-12-18 05:22:08
问题 I would like to create either a Thread or a Process which runs forever in a While True loop. I need to send and receive data to the worker in the form for queues, either a multiprocessing.Queue() or a collections.deque(). I prefer to use collections.deque() as it is significantly faster. I also need to be able to kill the worker eventually (as it runs in a while True loop. Here is some test code I've put together to try and understand the differences between Threads, Processes, Queues, and

Check if the Main Thread is still alive from another thread

怎甘沉沦 提交于 2019-12-18 04:23:32
问题 How can I check if the Main Thread is alive from another ( non-daemon, child ) thread? The child thread is a non-daemon thread and I'd like to check if the Main thread is still running or not, and stop this non-daemon thread based on the result. ( Making the thread daemon is not good for my situation because my thread writes to stdout which creates problems when the thread is set as a daemon) Using python 2.7 回答1: For Python 2.7 you can try this: for i in threading.enumerate(): if i.name ==

Taking in multiple inputs for a fixed time in Python [duplicate]

青春壹個敷衍的年華 提交于 2019-12-17 16:58:10
问题 This question already has answers here : Keyboard input with timeout? (13 answers) Closed last year . I'm using Python 3 and I wanted to code a program that asks for multiple user inputs for a certain amount of time. Here is my attempt at that: from threading import Timer ## def timeup(): global your_time your_time = False return your_time ## timeout = 5 your_Time = True t = Timer(timeout, timeup) t.start() ## while your_time == True: input() t.cancel() print('Stop typing!') The problem is,

Opening a Python thread in a new console window

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 09:54:28
问题 I am trying to make a program that will launch both a view window (console) and a command line. In the view window, it would show constant updates, while the command line window would use raw_input() to accept commands that affect the view window. I am thinking about using threads for this, but I have no idea how to launch a thread in a new console window. How would I do that? 回答1: Rather than use a console or terminal window, re-examine your problem. What you are trying to do is create a GUI

multiprocessing.pool.MaybeEncodingError: 'TypeError(“cannot serialize '_io.BufferedReader' object”,)'

筅森魡賤 提交于 2019-12-17 07:54:28
问题 Why does the code below work only with multiprocessing.dummy , but not with simple multiprocessing . import urllib.request #from multiprocessing.dummy import Pool #this works from multiprocessing import Pool urls = ['http://www.python.org', 'http://www.yahoo.com','http://www.scala.org', 'http://www.google.com'] if __name__ == '__main__': with Pool(5) as p: results = p.map(urllib.request.urlopen, urls) Error : Traceback (most recent call last): File "urlthreads.py", line 31, in <module>

multiprocessing.pool.MaybeEncodingError: 'TypeError(“cannot serialize '_io.BufferedReader' object”,)'

吃可爱长大的小学妹 提交于 2019-12-17 07:54:07
问题 Why does the code below work only with multiprocessing.dummy , but not with simple multiprocessing . import urllib.request #from multiprocessing.dummy import Pool #this works from multiprocessing import Pool urls = ['http://www.python.org', 'http://www.yahoo.com','http://www.scala.org', 'http://www.google.com'] if __name__ == '__main__': with Pool(5) as p: results = p.map(urllib.request.urlopen, urls) Error : Traceback (most recent call last): File "urlthreads.py", line 31, in <module>

How to access the GUI output?

泄露秘密 提交于 2019-12-13 10:32:06
问题 I'm developing one test bench which runs multiple tests via python gui and prints the output as below. A Passed B Passed C Passed D Passed E Passed Button from gui should be changed to 'Passed' only when A,B,C,D,E all are Passed. If any of these tests fails, it should say failed. What is the way to access this output from gui which is printed on screen. My code for tests is: from PyQt4.QtCore import * from PyQt4.QtGui import * import sys, os, time from PyQt4 import QtGui, QtCore from progress

How to write the map sentence here to call array to calculate with ThreadPool module?

我怕爱的太早我们不能终老 提交于 2019-12-13 06:58:58
问题 I want to make a practice with module ThreadPool,to add 2 for every element in range(1,100). from multiprocessing.pool import ThreadPool array=range(1,100) class test(): def myadd(self,x): return(x+2) do=ThreadPool(5) do.map(test.myadd,array) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Python34\lib\multiprocessing\pool.py", line 255, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "D:\Python34\lib\multiprocessing\pool.py", line