multithreading

serial port thread locking while processing data read from serial port

删除回忆录丶 提交于 2020-01-24 21:35:26
问题 I have an event handler that gets called anytime data is received on a serial port, once this event is called I process an individual byte of data until all data is processed. My question is, how do I make sure that this IBSerialPort_DataReceived event handler doesn't get called again asynchronously while I am stilling processing bytes from the first time it was called, ie I want to guarantee the ProcessByte method is only ever executing on one thread at a time. void IBSerialPort_DataReceived

wxPython, capturing an output from subprocess in real-time

巧了我就是萌 提交于 2020-01-24 21:06:02
问题 I'm working on application in wxPython which is a GUI for a command line utility. In the GUI there is a text control which should display the output from the application. I'm launching the shell command using subprocess, but I don't get any output from it until it has completed. I have tried several solutions but none of them seems to work. Below is the code I'm using at the moment (updated): def onOk(self,event): self.getControl('infotxt').Clear() try: thread = threading.Thread(target=self

wxPython, capturing an output from subprocess in real-time

送分小仙女□ 提交于 2020-01-24 21:05:07
问题 I'm working on application in wxPython which is a GUI for a command line utility. In the GUI there is a text control which should display the output from the application. I'm launching the shell command using subprocess, but I don't get any output from it until it has completed. I have tried several solutions but none of them seems to work. Below is the code I'm using at the moment (updated): def onOk(self,event): self.getControl('infotxt').Clear() try: thread = threading.Thread(target=self

Using Task.Run() for Linq - optimization or bottleneck

≡放荡痞女 提交于 2020-01-24 20:45:09
问题 I'm in the process of trying to optimize a few older projects, making sure they're "async all the way" and won't crash under heavier loads. I've used variations of the snippet below and feel unsure if the Task.Run is an optimization or a possible bottleneck. This method gets quite heavy use in some of the larger forms. public static Task<List<SelectListItem>> ToMultipleSelectListItems<T>(this List<T> items, Func<T, string> nameSelector, Func<T, Guid> valueSelector, List<Guid> selected, Func<T

C#, Maximize Thread Concurrency

混江龙づ霸主 提交于 2020-01-24 20:37:20
问题 With the help of Google and community, I was able to build a nice set of methods allowing me to asynchronously call a function. This function is testing remote host properties, so it is idling most of the time. For this reason I would like to maximize the number of concurrent threads launched such that all calls can be processed in the minimum amount of time. Here is the Code I have so far: // Check remote host connectivity public static class CheckRemoteHost { // Private Class members

Runnable posted in another runnable not executed

戏子无情 提交于 2020-01-24 20:22:04
问题 I'm trying to run a runnable from another runnable using Handler.post() method of my singleton but this second runnable is not being run until after the original runnable finishes. In the example code below I am calling MyManager,getInstance().startCommand() from somewhere in the application. The myRun variable in the MyCommand class has a sleep put on the thread so I can test a timeout feature, but the runnable called mTimeoutTimer is not be executed until AFTER the myRun runnable is

sendMessage from outside in autobahn running in separate thread by using “asyncio”

泪湿孤枕 提交于 2020-01-24 20:00:11
问题 I want to call sendMessage method from outside of MyServerProtocol class and send a message to the server. The answare is very similar to this but i need to use asyncio instead of twisted . Cane someone suggest me a solution? An example derived from this would also be appreciated Thanks. 回答1: The call_soon_threadsafe function of event loop is meant for this. from autobahn.asyncio.websocket import WebSocketServerProtocol, \ WebSocketServerFactory class MyServerProtocol(WebSocketServerProtocol)

Kotlin to achieve multithread request hedging?

依然范特西╮ 提交于 2020-01-24 18:55:47
问题 Spring's reactor has an interesting feature : Hedging . It means spawning many requests and get the first returned result , and automatically clean other contexts. Josh Long recently has been actively promoting this feature. Googling Spring reactor hedging shows relative results. If anybody is curious , here is the sample code . In short , Flux.first() simplifies all the underlaying hassles , which is very impressive. I wonder how this can be achieved with Kotlin's coroutine and multithread ,

Kotlin to achieve multithread request hedging?

核能气质少年 提交于 2020-01-24 18:55:31
问题 Spring's reactor has an interesting feature : Hedging . It means spawning many requests and get the first returned result , and automatically clean other contexts. Josh Long recently has been actively promoting this feature. Googling Spring reactor hedging shows relative results. If anybody is curious , here is the sample code . In short , Flux.first() simplifies all the underlaying hassles , which is very impressive. I wonder how this can be achieved with Kotlin's coroutine and multithread ,

When will awaiting a method exit the program?

佐手、 提交于 2020-01-24 17:55:31
问题 I've been reading the following post, specifically this point: On your application’s entry point method, e.g. Main. When you await an instance that’s not yet completed, execution returns to the caller of the method. In the case of Main, this would return out of Main, effectively ending the program. I've been trying to do that, but I can't seem to make it exit. Here's the code I have: class Program { // ending main!!! static async Task Main(string[] args) { Task<Task<string>> t = new Task<Task