Questions tagged [python-multithreading]

python-multithreading refers to how to divide work into multiple streams of execution in Python.

python-multithreading refers to how to divide work into multiple streams of execution within a single process in Python. Usually this refers to the threading module. It could also refer to concurrent.futures.ThreadPoolExecutor or the thread/_thread module.

More information:

3995 questions
1
vote
1 answer

Flask object has no attribute app_context

I'm trying to send emails periodically with flask mail, but I'm stuck with this error: Flask object has no attribute app_context def mail_periodic(): print "sending mail at " +time.ctime() app = current_app._get_current_object() msg =…
1
vote
1 answer

Tkinter: Scheduling Sequential Threads executed via button clicks

I have a Tkinter GUI with multiple buttons each which call different functions using threads. I have to automate the clicking of the buttons in sequence. So I am using a single START button, which will click first button, wait for the respective…
1
vote
1 answer

Python threading and multiprocessing

This is my code: from threading import Thread from multiprocessing import Process def foo(x, y): x += 5 y.append(5) if __name__ == '__main__': x = 0 y = [] thread = Thread(target=foo, args=(x, y,)) thread.start() …
1
vote
0 answers

Unable to repopulate a queue in python 3

The code is getting exited when I run the following code import mysql.connector import mysql.connector.pooling as x import time from threading import Thread from queue import Queue dbconfig = { "database": "mydb", …
Subramanian
  • 67
  • 1
  • 10
1
vote
2 answers

Python multi threading spawning n concurrent threads

I am new to Python threading, I have tried the below code to understand the threads: import threading def sq(num): for n in num: print("calculating square") print('square={}'.format(n*n)) numbers=[10,20,30,40,50,60] t1 =…
1
vote
2 answers

python threading to have same behaviour as fork

I've just started in python and with threading module. I used forks in C and the behaviour is that when fork is executed both threads keep on the same line of code. I was wondering how can I do that since I'm not able to do it. If I do not specify a…
muniategui
  • 73
  • 1
  • 5
1
vote
4 answers

How can I create non-blocking threads?

I have been trying to use Threads in python. I am working on a Pi hardware project. Here's the problem: When I create a thread, and call it like this, the loop keeps creating new threads before the old ones are completed. Hence, slowing the program…
embedded.95
  • 63
  • 1
  • 8
1
vote
0 answers

Python Really Thread Safe Dictionary ("RuntimeError: dictionary changed size during iteration" avoidance)

I've accidentialy got a threaded application due to the use of web.py and pyinotify packages :) The application keeps sorta state in JSON files, which it may change and which can be changed by anyone else. Changed JSON is reloaded back into a dict…
1
vote
1 answer

If I am listening to a websocket in one thread and running a function in another thread is it possible to miss messages

Title says it all really. I am running a program on a Linux EC2 instance with 4 threads. Three of these are listening to different websockets and the final one is webscraping and calling off a set of other functions when needed. Is it possible that…
lordf
  • 70
  • 1
  • 12
1
vote
0 answers

Stop multiples threads if error ocurred and keep running the main thread ? Python

Is there a way to stop all threads in the list if an error occurs in any of them without stopping the main thread ? from threading import Thread def build_packages(pkg_id): try: # do something except Exception: # stop all…
1
vote
2 answers

ThreadPoolExecutor fails when run with manage.py

# test.py # python 3.4.5 import time from concurrent.futures import ThreadPoolExecutor def a(): time.sleep(1) print("success") executor = ThreadPoolExecutor(1) executor.submit(a).result() The above snippet works when run like $ python…
Filip Kilibarda
  • 2,484
  • 2
  • 20
  • 31
1
vote
1 answer

Run a class function in background and retrieve its status

import threading from azure.storage.blob import BlockBlobService def do_other_stuff(): print("so much stuff to do") class ABlob: def __init__(self, account_name, account_key, container_name, blob_name, file_path): self.account_name…
1
vote
1 answer

Asynchronous import in Python

I need to import something large and computationally expensive but don't need it right away in my application. Is there a way to import something asynchronously in python, i.e. have whatever the import needs to do be done in the background while my…
1
vote
1 answer

How to return thread's first argument along with thread's return from queue?

Below I have the Threader class, which I use to thread an arbitrary number of functions, then return a list of the threaded functions' returns after joining the threads. One feature I want is the option to return a dictionary instead of a list. I…
1
vote
1 answer

Getting asyncio to run a function in order (Python 3)

Here is a simple example of using asyncio to print out numbers from 0 to 9. Problem: Sometimes the code prints out the numbers from 0 to 7, then prints 9, then 8. Especially when you set ThreadPoolExecutor to a smaller number like 4 or…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
1 2 3
99
100