python-multithreading

Events for stopping Threads vs ThreadPoolExecutor

Events for stopping Threads vs ThreadPoolExecutor Question: I’m trying to understand all the differences between using a ThreadPoolExecutor and just using threads in python. I tried to use a threadpoolexecutor, and it seemed to act as a blocking function (the context didnt seem to move on and allow the main thread to continue). When I …

Total answers: 1

How do you make faster A.P.I calls using multithreading without using requests in Python?

How do you make faster A.P.I calls using multithreading without using requests in Python? Question: I’m trying to receive historical stock data for every company in the S&P 500. The problem is that it is taking a really longtime to get the data. from ApiStuff import ApiStuff import fundamentalanalysis as fa import pickle tickers = …

Total answers: 2

Python – Mock/trigger file creation event while monitoring it in same script/thread?

Python – Mock/trigger file creation event while monitoring it in same script/thread? Question: I’m writing a test script and use below function detect_event_and_get_json_data() to monitor for newly Json created event/s in a json_path and parse these data for checking. But the problem is: inside this while loop for waiting Json event/s, is there any way …

Total answers: 1

Python3 : How to spawn jobs in parallel

Python3 : How to spawn jobs in parallel Question: I am pretty new to multithreading and would like to explore. I have a json file, that provides some config. Based on this, i need to kick off some processing. Here is the config { "job1":{ "param1":"val1", "param2":"val2" }, "job2":{ "param3":"val3", "param4":"val4" } } and here …

Total answers: 2

tkinter mainloop() not ending the script once it completes

tkinter mainloop() not ending the script once it completes Question: For some reason the mainloop() is not ending. The final print statement never gets triggered but everything else does. Any idea what is causing this or how to resolve it? It happens even without the threading. import time from tkinter.filedialog import askdirectory from tkinter import …

Total answers: 3

Using multithreading with time.sleep and unique loggers

Using multithreading with time.sleep and unique loggers Question: I’m trying to make sure that several threads start as close to each other as possible, and for that I’m using time.sleep. Each thread will have its own logger, which will output to its unique file. There’s something very strange happening though… Sometimes, not all logger files …

Total answers: 1

Close pyplot and reopen with updated data from another thread

Close pyplot and reopen with updated data from another thread Question: I am trying to display a pyplot that updates every 3 seconds with data from another thread. I need to close the plot and reopen with the updated variables. I do not need an animation, I want to close the figure and open a …

Total answers: 1

Multithreaded python program performance loss after laptop upgrade

Multithreaded python program performance loss after laptop upgrade Question: I have been having this weird issue where my new laptop handles an albeit computationally intensive program I wrote worse than my last one. The code is a python program I wrote that measures errors in a numerical model for a large set of data. It …

Total answers: 2

Appending to a list with multithreading ThreadPoolExecutor and map

Appending to a list with multithreading ThreadPoolExecutor and map Question: I have the following code import random import csv from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ProcessPoolExecutor import pandas as pd def generate_username(id, job_location): number = "{:03d}".format(random.randrange(1, 999)) return "".join([id, job_location.strip(), str(number)]) def append_to_list(l, idx, job_location): l.append([idx, generate_username(str(idx), job_location)]) def generate_csv(filepath, df): rows = [["EMP_ID", …

Total answers: 1