5 ms·
Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary https://wiki.python.org/moin/PythonDecoratorLibrary A
by thebigspacefuck 10y ago
Another page you might be interested in bookmarking:
https://wiki.python.org/moin/PythonDecoratorLibrary https://wiki.python.org/moin/PythonDecoratorLibrary
A similar decorator to thread function calls for concurrency:
https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thunkify https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...
- lqdc13 10y agoA lot of these need to be updated. For one, they don't follow PEP8. Secondly, unfortunately, the signal thing doesn't work on Windows and the threading thing is a bad example because it simulates multiplication, but if you actually had a CPU intensive task, there would be no performance benefits.
- stanislavb 10y agoAnd here they are a few more decorators https://python.libhunt.com/categories/284-concurrency-and-parallelism https://python.libhunt.com/categories/284-concurrency-and-pa...
- elpres 10y agoDoesn't this second decorator only work with functions doing IO or releasing the GIL in any other way (like time.sleep() that they use in the example)? If all the function is doing is actual computation (i.e. using the CPU), no other code can run in parallel with it because of the GIL.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- thebigspacefuck 10y agoYes, that's right, it is best used for I/O-bound applications. You could use it for: * running multiple Database queries * SSH-ing into multiple devices to run a command * loading multiple web pages * calling multiple APIs
- deleted 10y ago[deleted]
- hcarvalhoalves 10y agoNever heard this name for this pattern (thunk). Isn't this the same as a Future/Promise object?
- issaria 10y agoThunk is from haskell,.