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

broker.py is not waiting for all threads to be finished #59

Closed
crane-denny opened this issue Sep 1, 2014 · 4 comments
Closed

broker.py is not waiting for all threads to be finished #59

crane-denny opened this issue Sep 1, 2014 · 4 comments
Assignees
Milestone

Comments

@crane-denny
Copy link
Contributor

I did not dig now very deep into it.

If I run a script which adds and removes some IPs form an interface the scripts ends before all threads are done yet.
Would be nice if loop.py would catch this and block until all threads are finished.

Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
File "/usr/local/lib/python2.7/dist-packages/pyroute2/iocore/broker.py", line 152, in run
File "/usr/lib/python2.7/threading.py", line 404, in wait
File "/usr/lib/python2.7/threading.py", line 259, in wait
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

@svinota svinota added the bug label Sep 1, 2014
@svinota svinota self-assigned this Sep 1, 2014
@svinota svinota added this to the 0.2.15 milestone Sep 1, 2014
@svinota
Copy link
Owner

svinota commented Sep 1, 2014

Thanks for reporting!

svinota added a commit that referenced this issue Sep 1, 2014
Please note, that the Python interpreter shutdown w/o `IPRoute.release()`
of `IPDB.release()` is permitted now only in the interactive mode.

In scripts, it is required to call `.release()` routines before exit.

Bug-Url: #59
@svinota
Copy link
Owner

svinota commented Sep 1, 2014

Fixed. Please notice, that now usage of .release() routines is required :

from pyroute2 import IPRoute
ip = IPRoute()
[…]
ip.release()

and the same for IPDB:

from pyroute2 import IPDB
ipdb = IPDB()
[…]
ipdb.release()

The .release() routine must be called even in the case of exceptions, so it is better to call it from finally clause:

from pyroute2 import IPRoute
ip = IPRoute()
try:
    […]
except […]:
    […]
finally:
    ip.release()

I had to remove the deamonic flag from threads a long time ago, but didn't 'cause of the interactive interpreter. Now they become daemons only when one runs pyroute2 from the interactive Python shell, otherwise one must explicitly call .release() to initiate the shutdown sequence of the object.

Is that ok?

@crane-denny
Copy link
Contributor Author

works like a charm!
Thx for the quick fix. :)

@svinota
Copy link
Owner

svinota commented Sep 1, 2014

You're welcome!

@svinota svinota added fixed and removed on check labels Sep 1, 2014
@svinota svinota closed this as completed Sep 1, 2014
svinota pushed a commit that referenced this issue Dec 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants