vmware-archive / wavefront-django-sdk-python

Apache License 2.0
2 stars 3 forks source link

Wavefront prevents main thread from exiting #6

Open AgDude opened 5 years ago

AgDude commented 5 years ago

With wavefront configured, open a django shell: python manage.py shell then Exit the shell with exit()

start the django development server like python manage.py runserver, then type ctrl-c to stop the server.

In both of these cases the process hangs indefinitely, and does not exit.

The autoreload on file changes for the development server also does not work with wavefront configured.

AgDude commented 5 years ago

This appears to be caused by the use of threading.Timer() in both the HeartbeaterService and the WavefrontDirectClient. In the case of the HeartbeaterService the interval is 5 minutes, which will cause the main thread to block for that long if it tries to exit without closing the heartbeater first.

AgDude commented 5 years ago

This issue is going to prevent us from moving this into production. I have observed this currently with both runserver and shell, but it appears it will impact server processes as well, which are expected to exit or restart based on signals.

AgDude commented 5 years ago

It looks like this could be addressed by setting _timer.daemon = True everywhere a timer is used.

This does have the implication of losing pending messages before they are sent if the client is not properly closed. Personally I would consider that a seperate issue, and it could either be left to the application developer to implement handlers to properly close connections, or the SDK could listen for SIGINT and cleanly close the clients/reporters.

michi88 commented 3 years ago

Is this now fixed with https://github.com/wavefrontHQ/wavefront-sdk-python/pull/48 ?