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

pending tasks in loop #24

Closed
benoitc opened this issue Sep 5, 2012 · 5 comments
Closed

pending tasks in loop #24

benoitc opened this issue Sep 5, 2012 · 5 comments

Comments

@benoitc
Copy link
Contributor

benoitc commented Sep 5, 2012

It seems that active_handlers only return the number of active handlers at a a time but not return the real number of pending tasks. For example I can have one pending ticker not showing as active; should I reference all the loop tasks unsing ref() ?

@saghul
Copy link
Owner

saghul commented Sep 5, 2012

active_handles is a libuv internal thing which shouldn't be in pyuv, so I'll probably remove it for 0.9.0, so don't rely on it.

loop.run() will return when no handle is holding a reference to it. Handles hold a reference to the loop when they are active, but you can unref() a handle after you start it if you don't want it to keep the loop alive.

I guess that you are dealing with the "how do I stop the loop" problem then. You can use loop.walk and close all handles, for example:

def cb(handle):
    if not handle.closed:
        handle.close()
loop.walk(cb)

Hope this helps.

@benoitc
Copy link
Contributor Author

benoitc commented Sep 5, 2012

mm I have a heartbeat running in background to make sure the loop event handler is part of the tasks. Not sure in this case how I can do.If I unref it most probably the loop will close if no other handle is running I guess

@saghul
Copy link
Owner

saghul commented Sep 5, 2012

Exactly. If you don't want the heartbeat to keep the loop alive unref() it after you start it. I usually do this for Signal handles, for example.

@benoitc
Copy link
Contributor Author

benoitc commented Sep 5, 2012

OK thanks. This is finally what I do in flower:

benoitc/flower@294ed5a

The loop task will run until no pending events exists. A timer make sure that the loop let other tasks running.

@benoitc
Copy link
Contributor Author

benoitc commented Sep 10, 2012

ok figured it. Closing the issue. Thanks for your answer.

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