multithreading

Multithreading to Scrape Yahoo Finance

纵然是瞬间 提交于 2021-02-08 11:49:44
问题 I'm running a program to pull some info from Yahoo! Finance. It runs fine as a For loop, however it takes a long time (about 10 minutes for 7,000 inputs) because it has to process each request.get(url) individually (or am I mistaken on the major bottlenecker?) Anyway, I came across multithreading as a potential solution. This is what I have tried: import requests import pprint import threading with open('MFTop30MinusAFew.txt', 'r') as ins: #input file for tickers for line in ins: ticker_array

C# best way to implement TCP Client Server Application

家住魔仙堡 提交于 2021-02-08 11:42:19
问题 I want to extend my experience with the .NET framework and want to build a client/server application. Actually, the client/server is a small Point Of Sale system but first, I want to focus on the communication between server and client. In the future, I want to make it a WPF application but for now, I simply started with a console application. 2 functionalities: client(s) receive(s) a dataset and every 15/30min an update with changed prices/new products (So the code will be in a Async method

How do I return a class object from a thread and create a vector of returned objects?

主宰稳场 提交于 2021-02-08 11:37:59
问题 I want to use C++11 std::thread . I am writing a code to parse JSON files and the parsing is not dependent on each other. I have 900 files and to increase the speed of execution I want to create as many threads and make the execution parallel. My problem is at the moment the function I want to pass to the std::thread is a function of a class and it returns the parsed object as a JSON object from which I create a std::vector . I googled 'returning values from threads' and I am getting the

How do I return a class object from a thread and create a vector of returned objects?

我的未来我决定 提交于 2021-02-08 11:37:46
问题 I want to use C++11 std::thread . I am writing a code to parse JSON files and the parsing is not dependent on each other. I have 900 files and to increase the speed of execution I want to create as many threads and make the execution parallel. My problem is at the moment the function I want to pass to the std::thread is a function of a class and it returns the parsed object as a JSON object from which I create a std::vector . I googled 'returning values from threads' and I am getting the

Creating a thread in C#

十年热恋 提交于 2021-02-08 11:03:07
问题 How would I go about in creating a thread in C#? In java I would either implement the Runnable interface class MyThread implements Runnable{ public void run(){ //metthod } and then MyThread mt = new MyThread; Thread tt = new Thread(mt); tt.start() or I could simply extend the Thread class class MyThread extends Thread{ public void run(){ //method body } and then MyThread mt = new MyThread mt.start(); 回答1: No, contrary to Java, in .NET you can't extend the Thread class because it's sealed. So

Creating a thread in C#

戏子无情 提交于 2021-02-08 11:01:35
问题 How would I go about in creating a thread in C#? In java I would either implement the Runnable interface class MyThread implements Runnable{ public void run(){ //metthod } and then MyThread mt = new MyThread; Thread tt = new Thread(mt); tt.start() or I could simply extend the Thread class class MyThread extends Thread{ public void run(){ //method body } and then MyThread mt = new MyThread mt.start(); 回答1: No, contrary to Java, in .NET you can't extend the Thread class because it's sealed. So

Using boost::asio::deadline_timer inside a thread

这一生的挚爱 提交于 2021-02-08 10:42:28
问题 I used boost::asio::deadline_timer to run a function. I have MosquitoInterface class as follow class MosquitoInterface{ MosquitoInterface(deadline_timer &timer) : t(timer){} } Inside my main.c int main(int argc, char** argv ) { io_service io; deadline_timer t(io); MosquitoInterface *m = new MosquitoInterface(t); io.run(); d = new Detectdirection(); while(run) { int ret = d->Tracking(); if(ret < 0) cout << "Pattern is not found" << endl ; } if(d!=NULL) delete d; if(m!=NULL) delete m; cout <<

How is a thread waiting for mutex put back to running?

我们两清 提交于 2021-02-08 10:28:59
问题 The context is like this: a thread tries to lock a already locked mutex the thread is put to sleep/blocking after some while, the mutex is unlocked Q1) What will happen then ? will the thread be immediately put back to running? Or kernel will still wait the running thread consume its time slice and schedule the waiting thread normally? Q2) What if the mutex is not unlocked forever? How does the kernel determine to keep the thread waiting? 回答1: Will the thread be immediately put back to

Tkinter, Popen, and threads

自闭症网瘾萝莉.ら 提交于 2021-02-08 10:27:25
问题 I have a need from a Tkinter GUI to be able to start a long-running Linux script but at the same time I want to be able to have a stop-button enable so I can stop the process. Neither Tkinter nor popen are threadsafe. I thought of simply either placing the popen function in a thread or possibly just enabling a button in a thread. I am currently using Red Hat Linux 5.9 which uses Python 2.4.3, but I have later versions available online that I could use. In the program, below note that I

New Thread.Sleep behaviour under Windows 10 October Update 20H2

大憨熊 提交于 2021-02-08 10:22:58
问题 So I have thrown together a quick repro to highlight the issue while helping myself to understand what on earth was going on in my main app, after receiving many user reports of sudden slow behaviour out of nowhere after more than a year without issue. An active user of my application pointed out that the problem only came about after a recent Windows update, it led me to verify that it was indeed caused by the October Update 20H2. using System; using System.Diagnostics; using System