Comments by "Lawrence D’Oliveiro" (@lawrencedoliveiro9104) on "ArjanCodes"
channel.
-
33
-
11
-
10
-
8
-
8
-
6
-
6
-
5
-
5
-
5
-
4
-
4
-
4
-
4
-
3
-
3
-
3
-
3
-
3
-
3
-
2
-
2
-
2
-
2
-
2
-
I notice you only talked about function decorators, not class decorators. They have their uses, too.
I think the most extensive use I have made of custom decorators so far has been in my DBussy package, a pure-Python wrapper for libdbus. The information defining the D-Bus interface to a Python class is specified via a function decorator on each Python method implementing a D-Bus interface method, with a class decorator to tie it all together. Then when you register your class to receive messages, the dispatch mechanism knows how to decode incoming D-Bus method calls, convert the arguments and dispatch to the appropriate Python method.
As a bonus, this same information is used to automatically generate the D-Bus XML introspection format, when another D-Bus peer sends you the introspection message. And conversely, when you introspect another D-Bus peer, this info is used to dynamically generate a “proxy interface class” -- a Python class whose methods simply send the appropriate D-Bus messages and return the responses.
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
@zacharythatcher7328 Threads are not an alternative to callbacks. Threaded event loops (in fact, threaded everything) were all the rage in the 1990s, until it was realized that they made the code very hard to debug. That’s why we now stick to single-threaded event loops, select(2)/poll(2)/epoll(2) etc. But then, time-consuming tasks required the use of callbacks to maximize responsiveness, until the old technique of coroutines was revived more recently as a way to make such code more readable. This has required language changes, but a lot of languages (Python included) have adopted those changes.
What Arjan is using threads for here, and what I have done with them myself, is to turn blocking calls into non-blocking ones. That’s all. Luckily, in POSIX, “blocking” normally means “thread-blocking”, not “process-blocking”. That’s why we can get away with it. Again, it’s all in the cause of maximizing responsiveness, without getting back into the hell of full-on multithreading.
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1