Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add running() method to Future #106

Closed
dcnieho opened this issue Sep 30, 2022 · 3 comments
Closed

add running() method to Future #106

dcnieho opened this issue Sep 30, 2022 · 3 comments

Comments

@dcnieho
Copy link

dcnieho commented Sep 30, 2022

Through Pebble's futures i can distinguish whether a task is done or not, and whether it was cancelled or errored. However, when not done, i cannot find whether it is currently running or only pending. I have worked around this by routing all my tasks through a function that provides the notification that a job starts and keeping track of state using that and the done_callback, but this adds a bunch of complication. Would it be possible to add a running() method to your futures, that for instance sets some running flag in the future right before

result = process_execute(
gets executed?

@noxdafox
Copy link
Owner

noxdafox commented Sep 30, 2022

Hello,

I am not sure what is the issue here. Pebble's Futures inherit from concurrent.future.Future and have a running method.

In [1]: import pebble

In [2]: def function():
   ...:     import time
   ...:     time.sleep(100)
   ...: 

In [3]: pool = pebble.ProcessPool()

In [4]: f = pool.submit(function, None)

In [5]: f.running()
Out[5]: True

The method works as expected.

In [15]: for _ in range(100):
    ...:     f = pool.submit(function, None)
    ...: 

In [16]: f.running()
Out[16]: False

@dcnieho
Copy link
Author

dcnieho commented Sep 30, 2022

@noxdafox thank you very much for having a look. I wasn't aware of the difference between the future returned by processpool's submit and the asyncio support. I see now that the problem is that i use the asyncio support (https://pebble.readthedocs.io/en/latest/#pools-and-asyncio). The asyncio future does not have a running() method. Given how much complexity it'll save if i get a future that does have the running method, it worth it for me to try to redesign my solution to work without the asyncio support.

@dcnieho
Copy link
Author

dcnieho commented Sep 30, 2022

this can be closed i think, as implementing running() for asyncio.Future wouldn't be your responsibility of course. And a simplified design avoiding that did the trick for me nicely.

@dcnieho dcnieho closed this as completed Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants