D
D
deex2011-04-06 01:01:51
Python
deex, 2011-04-06 01:01:51

Python 3 and threads?

I started learning Python 3 and at the moment I'm trying to put threads into practice (concurrent.futures wrapper)
it comes out very buggy and I even know the reason - from not understanding their device
at the moment, I managed to learn two tricks for working with threads:
- using threading.Event, in order to set flags in the main thread that all threads can receive without problems
- using Queue - threads queue jobs, and the main thread checks the queue with a timer and executes these tasks (after that I abandoned pyqt signals and slots, because not I see the need for them)
But much still remains incomprehensible
- where is it better to call the addition of the task “decrease the counter of active threads in the GUI” to the queue - from process_result or a worker?
- Do I need to additionally call the counter decrement if the thread, for example, is canceled or crashed?
with this wild confusion - streams either go into the red, then 60 pieces just freeze
- is it possible to create a class for working with the config (config.ini) in the base class of the main thread and give the streams the ability to access it and read settings from it?
- if this causes problems, then how then to pass the settings to all files - only in the attributes of the start of the thread?
Well, I would still like to ask you to recommend some literature that could save me from such questions.
I want to know “what can” and “what can’t” be done in streams.
preferably, literature focused on python
also, I will not refuse the help of knowledgeable comrades - if you are ready to fill my head with valuable knowledge, I am ready to replenish your webmoney account :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Efros, 2011-04-08
@powerman

I'm sorry, I don't know "what can" and "what can't" be done in the threads of the third python, but once in two days no one answered the topic, I will answer a little off topic.
I would recommend instead of searching for "what is possible" and "what is impossible" to study "how to" work with threads in general. And then, already understanding what you want to get, study exactly how something similar can be done in the third python. And “it is necessary” to work with threads in the style of CSPis the simplest approach that turns multi-threaded programming from very complex, confusing and buggy. Unfortunately, it implies the use of a really large number of threads, which is impossible if each thread is allocated a fairly large stack (which is done by almost all implementations of threads in different languages ​​and operating systems). Therefore, you can “feel” this, for example, in the Go language, or in stackless python.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question