multithreading

Python Serial port event

房东的猫 提交于 2021-02-11 14:09:20
问题 I have an MCU connected to the computer through a serial interface. The MCU might send data at regular intervals or very seldom depending on the type of sensor connected to it. So I want to have a python function that gets called whenever there is data incoming from the serial port instead of polling all the time. After reading a lot of similar questions (Small Example for pyserial using Threading. PySerial/Arduino, PySerial/interrupt mode, Python Serial listener, and so on), I came to the

how to send incoming messages from socket client to GUI (pyqt5)

喜夏-厌秋 提交于 2021-02-11 13:59:56
问题 I am trying to make a chat application using socket library. I have three files server.py , client.py and gui.py listening process for client and server are provided by infinite loops. because of that server.py runs in another terminal window. but client and gui are running in one terminal window. the problem is when I call functions containing infinite loop it stuck there and the rest of code won't run. I even tried using multiprocessing , threading.Thread , threading.Timer , QThread and

How to pass objects from one thread class to another thread class in python

天涯浪子 提交于 2021-02-11 13:59:45
问题 I am using socket module in python to create two clients and one server. Client_1 shall send content of a .txt file to Client_2, through the server. In server I am using thread module to have a multiple client support. I have created three Threads in my server:- 1) First thread handles the client connections 2) Second thread receives the contents of the .txt file from Client_1 3) Third thread sends this contents to Client_2 The problem that I am facing, while executing the above mentioned

ProgressDialog not getting started in main thread

空扰寡人 提交于 2021-02-11 13:54:12
问题 I made an app which can upload some data to my database. In Activity, in which the user will enter data to be uploaded, i created a ProgressDialog. The ProgressDialog is created inside the onClick() method. In theory, it will be created because I'm not trying to make a ProgerssDialog in a thread other than Main UI Thread. Still, it's not being shown. I don't know why. package com.example.demoapp; import android.widget.*; import android.app.Activity; import android.app.ProgressDialog; import

JavaScript: Does an async function create a new thread?

ぃ、小莉子 提交于 2021-02-11 13:52:48
问题 Mozilla’s documentation on XMLHttpRequest includes the following on the async parameter: Note: Synchronous requests on the main thread can be easily disruptive to the user experience and should be avoided; in fact, many browsers have deprecated synchronous XHR support on the main thread entirely. That makes sense, as you don’t what to hold up the main thread waiting for an indeterminate period of time. If I create an async function which includes usng XMLHttpRequest , would that qualify as a

Using ObservableCollection across UI and Non-UI threads

我是研究僧i 提交于 2021-02-11 13:38:57
问题 I am using the SortableObservableCollection described here. Now I'd like to manipulate it from a UI or a non-UI thread so I tried the solution described here: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Runtime; using System.Windows.Data; public class SortableObservableCollection<T> : ObservableCollection<T> { private object _itemsLock = new object(); public SortableObservableCollection() : base() { BindingOperations

Play sound asynchronously in Python

随声附和 提交于 2021-02-11 13:36:54
问题 I have a while loop for my cameras(with opencv) to take a photos when something moves. I would like to call a function to play a sound as well. But when I call and play it, it will stop looping for that execution time. I tried ThreadPoolExecutor but had no idea how could I blend it with my code, because I'm not passing anything to the function. Just calling it from loop. Btw. I would like to be able to play it multiple times (multiple executions in time of execution) if multiple something in

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

What's the best way to create a new UI thread and call back methods on the original thread?

你。 提交于 2021-02-11 12:49:35
问题 I'm writing a plug-in class for a third-party GUI application. The application calls the Run method of my class, passing me a vendor-defined Context object. Any methods or properties in this Context object must be called from the current thread (that is, the application's UI thread). My plug-in code creates a WPF Window and shows it to the user. Some interactions need to call the Context object's methods, but some take time to run. This, of course, freezes my UI. Normally, I would call slow

Replay Kafka topic with Server-Sent-Events

Deadly 提交于 2021-02-11 12:35:45
问题 I'm thinking about the following use-case and would like to validate if this approach is conceptually valid. The goal is to expose a long-running Server-Sent-Event (SSE) endpoint in Spring replaying the same Kafka topic for each incoming connection (with some user-specific filtering). The SSE is exposed in this way: @GetMapping("/sse") public SseEmitter sse() { SseEmitter sseEmitter = new SseEmitter(); Executors .newSingleThreadExecutor() .execute(() -> dummyDataProducer.generate() // kafka