Comments (3)
Goal with pebble is not to be concurrent.futures
compatible. Only in recent versions I adopted a somewhat similar API to make it more friendly and also to re-use the Future
class.
I find the Executor
API pretty simplistic and I don't think that adding a custom namespace _pebble_specific_timeout
is the correct solution.
I will reinstate the schedule
API as the recommended function for submitting jobs to the Pools and leave the submit
for mere compatibility with asyncio.loop.run_in_executor
.
Main point here is that there are 2 sets of parameters/arguments:
- The ones which are Pool specific (what to run and how)
- The ones that are function specific (the function args and kwargs)
The two should be logically separated and not intertwined.
from pebble.
Hello,
the pool.submit
has been designed to be compatible with concurrent.future.Executor.submit
for the sake of supporting asyncio.loop.run_in_executor
API.
The concurrent.future.Executor.submit
API passes arguments and keyword arguments straight to the submitted function making positional arguments the only way to provide submission specific parameters.
This is evident in the function signature Executor.submit(fn, /, *args, **kwargs)
note the /
marking positional only parameters.
It would not be possible, in fact, to provide a signature such as ProcessPool.submit(fn, *args, timeout=None, **kwargs)
as this would prevent submitting functions with a timeout
keyword arguments such as requests.get
. Moreover, the above API would not allow to submit jobs within asyncio.loop.run_in_executor
as it would not be possible to submit them altogether with a timeout.
If you want to use ThreadPool
and ProcessPool
interchangeably and you don't care about the timeout functionality then you can simply use a class wrapper for it.
class Pool:
def __init__(pool: [pebble.ProcessPool, pebble.ThreadPool]):
self._pool = pool
def submit(fn, *args, **kwargs):
if isinstance(self._pool, pebble.ProcessPool):
self._pool.submit(fn, None, *args, **kwargs)
pool = Pool(pebble.ProcessPool())
futures = [pool.submit(func, i) for i in range(10)]
Keep in mind that ThreadPool
and ProcessPool
do not provide the same behaviour. Futures returned by ProcessPool
can be cancelled and can timeout. In such cases, the underlying process will be interrupted avoiding to consume extra resources. The same is not true for ThreadPool
due to the fact that running threads cannot be interrupted. Hence, you need to keep this aspect in mind when exchanging one pool with the other.
from pebble.
Thanks a lot for the enlightening remarks on the rationale behind such a design decision.
I see that the positional timeout
argument was added mainly to be compatible with libs like asyncio.
Coming from concurrent.futures, however, I was surprised by the subtle incompatibity in the API. I personallly would have preferred full compatibility by adding a special keyword argument like pebble_timeout
, which also avoids the somewhat redundant use of None
in many cases.
from pebble.
Related Issues (20)
- getting the pid of the process HOT 5
- Feature Request: Finaliser Method HOT 2
- Type Hints HOT 1
- Support dill HOT 3
- user_done_callback fires too early on cancellation or timeout HOT 9
- add running() method to Future HOT 3
- Pebble when used with PyQT5 is generating multiple UI instances HOT 6
- Pebble wheels pushed to PyPI are incorrectly tagged HOT 3
- Bug: new `submit` function makes it impossible to call a function that has a `timeout` argument HOT 6
- Logging process name inside concurrent.process HOT 2
- How to handle errors when using pool.schedule HOT 1
- shutdown of main program HOT 2
- @concurrent.process returned future blocks/hangs on running(), cancelled(), done() calls HOT 2
- Get information about broken process HOT 4
- Documentation for Pebble indicates threads created with a ThreadPool are cancellable HOT 1
- Channel mutex timeout HOT 6
- Pool blocked when child process is OOM killed HOT 7
- Exception running the examples on README HOT 1
- stopping pool HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pebble.