I am new to twisted library and I am trying to understand how this is done, that operations in python / twisted are asynchronous. So far, I thought that only GUI platforms (Qt or javascript) make extensive use of event driven architecture.
data:
- Twisted programs run in a single thread = no multithreading
- reactors and deferred patterns are used: callbacks / errors are declared and the execution of everything is controlled by the main loop of the reactor
- a single processor can never do anything truly parallel, because it shares its resources between processes, etc. In parallel code execution, I mean that the programming platform (python, javascript, whatever) performs more than one sequence of operations (which can be performed, for example, using multithreading)
question 1
Python can be thought of as a high-level shell for the operating system. What are the OS functions (or C functions) that provide asynchronous operation? Whether there is a?
question 2
Q1 leads me to the idea that distorted asynchrony is not true asynchrony, as in Javascript. For example, in JavaScript, if we provide 3 different buttons, attach callback functions to them, and we click all three buttons - then 3 callbacks will be executed in parallel. Indeed, in parallel.
In Twisted - as I understand it - this is not true asynchrony - it is, say, approximated asynchrony, since no operations would be performed in parallel (from the point of view of the code, as I mentioned actually 3). In Twisted, the first n line of code (defining protocols, factories, connections, etc.) is an announcement of what will happen when the whole system starts. Nothing is working yet. The actual execution is executed, then reactor.run() started. I understand that reactor runtimes are based on a single while True that repeats through events. The reactor checks all pending tasks, processes them, sends their result to the queue (either for callbacks or for errors). In the next run of the cycle, they will be processed one more step. Thus, deferred execution is actually linear (although, from the outside, it seems to be executed in parallel). Is my interpretation correct?
I would appreciate it if someone could answer my questions and / or explain how asynchrony works on the twisted / python platform and how it relates to the operating system. Thanks in advance for the good explanations!
edit: asynchronous article links are very welcome!
source share