multithreading

Recognizing Blocked Swing EDT

安稳与你 提交于 2020-03-27 06:54:47
问题 How to know that EDT is blocked (not visually but by inspecting the thread itself)? is there a way? I'm on the way to my final university task for graduation that have bunch of charts , but have little knowledge of Swing EDT (Java generally). have look at this piece: SwingUtilities.invokeLater(new Runnable() { public void run() { // task here } }); If we do some tasks that modify gui component on the block (including calling another Thread) , is that already the correct approach? And since

Python Multiprocessing password cracker

醉酒当歌 提交于 2020-03-26 23:21:21
问题 I have been learning Python in my spare time for a small amount of time now and I set myself a challenge to build a password cracker for a very specific task, it was to test how effective the security on my ADSL Router was (not very) - using Wireshark I could quite clearly see how it was hashing the password over http and I developed some code to perform a wordlist attack. (I apologise if you think my code is badly written - you would probably be correct!). #!/usr/bin/env python import

Python and Webkit, watching serial port thread, how to avoid core dump running javascript

孤街浪徒 提交于 2020-03-26 04:48:21
问题 I'm writing a game that uses python and webkit, and a webpage is the front-end/GUI. The PC is connected to an Arduino that controls a coin hopper and other i/o. When the Arduino sends 'coinin' over serial, I capture this in a serial-watching thread, then run some javascript on the webpage to 'add' a coin to the game. For simplicity in troubleshooting, I set up an example that runs a test thread instead of reading serial, but the problem is the same. The thread tries to add a coin every second

How do I pass an async function to a thread target in Python?

谁说胖子不能爱 提交于 2020-03-26 03:43:47
问题 I have the following code: async some_callback(args): await some_function() and I need to give it to a Thread as a target: _thread = threading.Thread(target=some_callback, args=("some text")) _thread.start() The issue is that I get the error that "some_callback" is never awaited. Any ideas how can I solve this problem? 回答1: You can do it by adding function between to execute async: async def some_callback(args): await some_function() def between_callback(args): loop = asyncio.new_event_loop()

How do I pass an async function to a thread target in Python?

只谈情不闲聊 提交于 2020-03-26 03:40:10
问题 I have the following code: async some_callback(args): await some_function() and I need to give it to a Thread as a target: _thread = threading.Thread(target=some_callback, args=("some text")) _thread.start() The issue is that I get the error that "some_callback" is never awaited. Any ideas how can I solve this problem? 回答1: You can do it by adding function between to execute async: async def some_callback(args): await some_function() def between_callback(args): loop = asyncio.new_event_loop()

Running Pybind11 on a Single Thread

冷暖自知 提交于 2020-03-26 03:05:30
问题 Is it possible to have pybind11 start a python interpreter on a single thread within C++? I have a class that initializes the interpreter and calls a function in a python script. I would like to call this function on multiple threads that C++ creates. #include "pybind11/pybind11.h" #include <iostream> #include <thread> namespace py = pybind11; class callMyPythonFunctionFromCpp { callMyPythonFunctionFromCpp() { m_module = py::module::import("mypython_script_file"); } void myfunc() // trying to

How does the scope of the global variable in threads work?

一世执手 提交于 2020-03-25 18:03:12
问题 I have two threads running and I want them to wait for each other at a specific line using threading.Condition(). However it seems that the global variable v is not global. It is a different variable for each thread. Here is the minimum viable product: import threading lock = threading.Condition() v = 0 n = 2 def barrier(): with lock: global v v =+ 1 print("v is increased to " + str(v)) if v == n: print("v is equal to n") lock.notifyAll() print("v equals n") v = 0 else: lock.wait() class

For Loop for list of Objects with use Multithread in Python

余生颓废 提交于 2020-03-23 14:36:53
问题 I am new in Python, I had a program which loads one big CSV file where is over 100k lines, each line had 4 columns. In FOR loop I check for each row same duplicated list ( dlist ), this dlist is list of objects of DRef class which I load with another function DsRef class: from tqdm import tqdm from multiprocessing import Pool, cpu_count, freeze_support class DsRef: def __init__(self, pn, comp, comp_name, type, diff): self.pn = pn self.comp = comp self.comp_name = comp_name self.type = type

Is it necessary to have atomic flags in multi-threaded code?

守給你的承諾、 提交于 2020-03-23 11:56:39
问题 I was wondering if it is really necessary to have atomic flags in a multi-threaded code. For this problem, I focus on a common situation in multi-thread code: stopping threads by setting a flag. Let's assume following pseudo-code: is_running = 1; create_threads(stopper_thread, running_thread_A, running_thread_B, running_thread_C); stopper_thread running_thread_A running_thread_B running_thread_C ------------------------------------------------------------------------------------------- if (x)

How to process data from a file in parallel in several threads and write them into another file while keeping the original data order (C#)

北城以北 提交于 2020-03-23 09:02:20
问题 I would like to ask you rather a general question (even though I'm rather interested in how to achieve it in C#). I have a huge file which I want to read by chunks, process the chunks somehow in parallel in several threads to make the processing faster and then write the processed data to another file in the same order as the original data chunks were read (i.e. making sure that the first data chunk read from the input file will be processed and saved first in the output file, the second