Live data from Hacker News

Python Concurrency Decorators

github.com

41–50 of 51 posts

Re: Python Concurrency Decorators

#41

Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary A similar decorator to thread function calls for concurrency: https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...

Doesn'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.

Re: Python Concurrency Decorators

#42
post #41

Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary A similar decorator to thread function calls for concurrency: https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...

Doesn'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]

Re: Python Concurrency Decorators

#44
post #41

Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary A similar decorator to thread function calls for concurrency: https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...

Doesn'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]

Re: Python Concurrency Decorators

#45
post #41

Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary A similar decorator to thread function calls for concurrency: https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...

Doesn'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.

Yes, 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

Re: Python Concurrency Decorators

#46

Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary A similar decorator to thread function calls for concurrency: https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...

Never heard this name for this pattern (thunk). Isn't this the same as a Future/Promise object?

Re: Python Concurrency Decorators

#48
post #41

Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary A similar decorator to thread function calls for concurrency: https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...

Doesn'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]

Re: Python Concurrency Decorators

#49

Another page you might be interested in bookmarking: https://wiki.python.org/moin/PythonDecoratorLibrary A similar decorator to thread function calls for concurrency: https://wiki.python.org/moin/PythonDecoratorLibrary#Lazy_Thu...

Never heard this name for this pattern (thunk). Isn't this the same as a Future/Promise object?

Thunk is from haskell,.

Re: Python Concurrency Decorators

#50

A couple of things offhand: - It has Python 2 and 3 support - It's a wrapper for the Python built-in "multiprocessing" library - It spreads out work over all cores (so the abstraction hides the ability to control the pool) Seems like a great way to get your feet wet with multiprocessing in Python, but it likely has limited use in production...although certain infrastructures like resource limited containers might be…

Is there no way to specify the number of cores to use?

There is in the latest version. Using like @concurrent(...) passes all arguments directly to Pool(...)
Post reply on HN