python-multithreading

Apscheduler skipping job executions due to maximum number of instances

試著忘記壹切 提交于 2021-02-20 09:32:50
问题 I am trying to use APScheduler to run periodic jobs with an IntervalTrigger, I've intentionally set the maximum number of running instances to one because I don't want jobs to overlap. Problem is that after some time the scheduler starts reporting that the maximum number of running instance for a job have been reached even after it previously informed that the job finished successfully, I found this on the logs: 2015-10-28 22:17:42,137 INFO Running job "ping (trigger: interval[0:01:00], next

python threading method stuck

落花浮王杯 提交于 2021-02-17 05:27:10
问题 I have a class MyClass which creates 7 threads when it is initialized. One thread is a TCPServer, and the other six are objects of MyClass which the TCPServer uses to process requests. My intention is to create method which can run in the background of MyClass and maintain the 6 threads. The 6 threads correspond to 2 distributed objects obj1 and obj2 replicated with an implementation of Raft called PySyncObj. There are three threads per object. Each cluster of objects obj_1_cluster and obj_2

Threading event wait in django application

浪子不回头ぞ 提交于 2021-02-11 14:32:58
问题 I have DRF API consumed by a front-end application. I need to handle a special feature: the user clicks a button, he's being asked to scan a RFID card on an external device (he has 30 seconds to do so, he must not be able to do anything else during this time), then after the scan or timeout he gets the focus back. So far I've been able to deal with the scanning part, but troubles comes with the timeout. Here's my setup: The endpoint /rfid/create/ is called by the front when the user clicks

Why do these threads fail to work in parallel?

只谈情不闲聊 提交于 2021-02-11 13:01:51
问题 Why this code doesn't work in parallel? When the thread with odd number starts calculating its big number, other threads for some reason just wait for it to finish although they are supposed to do their own stuff. What am I missing? import threading, math, time class MyThread(threading.Thread): def __init__(self, num): super(MyThread, self).__init__() self.num = num def run(self): while True: with mutex: print(self.num, 'started') math.factorial(self.num % 2 * 100000000) with mutex: print

i get this error “RuntimeError: threads can only be started once” when i click close and then click run again

对着背影说爱祢 提交于 2021-02-11 12:40:52
问题 import threading from tkinter import * running = False def run(): global running c = 1 running = True while running: print(c) c += 1 run_thread = threading.Thread(target=run) def kill(): global running running = False root = Tk() button = Button(root, text='Run', command=run_thread.start) button.pack() button1 = Button(root, text='close', command=kill) button1.pack() button2 = Button(root, text='Terminate', command=root.destroy) button2.pack() root.mainloop() click here for error img....i'm

i get this error “RuntimeError: threads can only be started once” when i click close and then click run again

…衆ロ難τιáo~ 提交于 2021-02-11 12:39:20
问题 import threading from tkinter import * running = False def run(): global running c = 1 running = True while running: print(c) c += 1 run_thread = threading.Thread(target=run) def kill(): global running running = False root = Tk() button = Button(root, text='Run', command=run_thread.start) button.pack() button1 = Button(root, text='close', command=kill) button1.pack() button2 = Button(root, text='Terminate', command=root.destroy) button2.pack() root.mainloop() click here for error img....i'm

How to pass arguments to thread functions in Python

白昼怎懂夜的黑 提交于 2021-02-11 12:13:23
问题 I have raspberry pi where I am using python to create a small buzzer script. In the script if a condition becomes True , I need to print some information and also make buzzer sound. Buzzer sounds are made in two different format i.e. High and Low . In High , I have to run below code: GPIO.output(BUZZER, 1) time.sleep(5) GPIO.output(BUZZER, 0) GPIO.cleanup() so that buzzer make continuous sound for 5 sec. In Low , I have to run below code: for i in range(5): print(i) state = GPIO.input(BUZZER)

How to pass arguments to thread functions in Python

冷暖自知 提交于 2021-02-11 12:12:59
问题 I have raspberry pi where I am using python to create a small buzzer script. In the script if a condition becomes True , I need to print some information and also make buzzer sound. Buzzer sounds are made in two different format i.e. High and Low . In High , I have to run below code: GPIO.output(BUZZER, 1) time.sleep(5) GPIO.output(BUZZER, 0) GPIO.cleanup() so that buzzer make continuous sound for 5 sec. In Low , I have to run below code: for i in range(5): print(i) state = GPIO.input(BUZZER)

Threading in Jupyter notebook

和自甴很熟 提交于 2021-02-10 18:30:00
问题 I tried running the following code snippet in a Jupyter notebook: import threading import time def worker(): print(threading.current_thread().getName(), 'Starting') time.sleep(0.2) print(threading.current_thread().getName(), 'Exiting') def my_service(): print(threading.current_thread().getName(), 'Starting') time.sleep(0.3) print(threading.current_thread().getName(), 'Exiting') t = threading.Thread(name='my_service', target=my_service) w = threading.Thread(name='worker', target=worker) w2 =

Python - “can't pickle thread.lock” error when creating a thread under a multiprocess in Windows

浪子不回头ぞ 提交于 2021-02-10 16:00:00
问题 I'm getting stuck on what I think is a basic multiprocess and threading issue. I've got a multiprocess set up, and within this a thread. However, when I set up the thread class within the init function, I get the following error: "TypeError: can't pickle thread.lock objects". However, this does not happen if the thread is set up outside of the init function. Does anyone know why this is happening? Note I'm using Windows. Some code is below to illustrate the issue. As typed below, it runs fine