Skip to content

Conversation

@aleph-ra
Copy link

Corrects the error being thrown in the timeout example in README and makes it more meaningful by adding sleep to simulate tasks and printing results from processes that finish.

Corrects the error being thrown in the timeout example and makes it more meaningful by adding sleep to simulate tasks and printing results from processes that finish.
def function(foo, bar=0):
time.sleep(foo) # simulate a task
return foo
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bar is not used anymore, the original README was returning foo + bar.

with ProcessPool(max_workers=5, max_tasks=10) as pool:
for index in range(0, 10):
future = pool.schedule(function, [index], {'bar':1}, timeout=TIMEOUT_SECONDS)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use KW arguments properly to better indicate how to call this function.

future = pool.schedule(function, args=[index], kwargs={'bar':1}, timeout=TIMEOUT_SECONDS)

Copy link
Owner

@noxdafox noxdafox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

I did not understand what was the issue with the TimeoutError handling.

Could you please make the fixes as requested in the comments?

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

Successfully merging this pull request may close these issues.

2 participants