Skip to content

[Debugger Plugin] Exit TensorBoard on SIGINT even with debugger enabled #975

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

Merged
merged 5 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions tensorboard/plugins/debugger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This dashboard is in its **alpha release**. Some features are not yet fully func

To enable the debugger dashboard, pass the `debugger_port` flag to TensorBoard. TensorBoard will then both receive gRPC messages from and issue gRPC messages to model logic via this port.

This command demonstrates how to set the debugger port to 6064.
This command demonstrates how to set the debugger port to 6064.

```
tensorboard \
Expand Down Expand Up @@ -166,10 +166,21 @@ For example, suppose a tensor has a shape of (500, 100), applying a slicing of `

For each tensor, the time axis (history of the tensor's execution) is treated as an 1D array. Numpy-style slicing can be applied to time. For example, the default slicing of `-1` selects the most recent value. However, if the user changes that slicing parameter to `:`, the full history of the tensor will be shown (and the rank of the tensor being visualized is increased by 1).

# Limitations
# Frequently Asked Questions (FAQ)

## Q: How to exit the debugging?
Copy link
Member

Choose a reason for hiding this comment

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

Maybe: How to exit debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


Answer: Follow these steps to interrupt your TensorFlow program being debugged
and the TensorBoard process running the Debugger Plugin (*in that order*):

1. Send `SIGINT` to the TensorFlow program being debugged, e.g., by using
`Ctrl+C`.
2. Send `SIGINT` to the TensorBoard process running the Debugger Plugin, e.g.,
by using `Ctrl+C`.

# Limitations and Unknown Issues
Copy link
Member

Choose a reason for hiding this comment

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

nit: These are known (not unknown) issues.


The Debugger Plugin has the following limitations and known issues. We plan to
Copy link
Member

Choose a reason for hiding this comment

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

nit: Maybe lowercase debugger plugin to match other uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

fix them in future releases.

* Hitting Ctrl+C (issuing a SIGINT signal) might fail to terminate execution for a model that is instrumented with
`TensorBoardDebugWrapperSession` or its corresponding hook. The same limitation may be present in the tensorboard
process as well. In those cases, the user must manually
[kill](https://www.linux.com/learn/intro-to-linux/2017/5/how-kill-process-command-line) the processes.
* The debugger dashboard does not yet support multiple users debugging at once.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe change this phrasing to "debugger plugin" to match other mentions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

31 changes: 29 additions & 2 deletions tensorboard/plugins/debugger/interactive_debugger_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

import json
import platform
import signal
import sys
import threading

from six.moves import xrange # pylint:disable=redefined-builtin
import tensorflow as tf
from werkzeug import wrappers

Expand Down Expand Up @@ -69,6 +71,7 @@ def __init__(self, context):
"""
del context # Unused.
self._debugger_data_server = None
self._server_thread = None
self._grpc_port = None

def listen(self, grpc_port):
Expand Down Expand Up @@ -96,8 +99,32 @@ def listen(self, grpc_port):
interactive_debugger_server_lib.InteractiveDebuggerDataServer(
self._grpc_port))

threading.Thread(target=self._debugger_data_server.
start_the_debugger_data_receiving_server).start()
self._server_thread = threading.Thread(
target=self._debugger_data_server.
start_the_debugger_data_receiving_server)
self._server_thread.start()

signal.signal(signal.SIGINT, self.signal_handler)

def signal_handler(self, unused_signal, unused_frame):
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to note somewhere that this is required because of arguably a deficiency in grpc/python 2.7:
grpc/grpc#6999 (They marked it as wontfix somewhat unreasonably, I think, given that the debugger plugin is exactly that kind of "rare case" where this has an effect in the real world.) E.g. in python 3, Ctrl+C will successfully kill TensorBoard (actually, it requires two of them in a row, but still it's closer).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comments. Thanks.

if self._debugger_data_server and self._server_thread:
print('Stopping InteractiveDebuggerPlugin...')
# Enqueue a number of messages to the incoming message queue to try to
# let the debugged tensorflow runtime proceed past the current Session.run
# in the C++ layer and return to the Python layer, so the SIGINT handler
# registered there may be triggered.
for _ in xrange(len(self._debugger_data_server.breakpoints) + 1):
Copy link
Member

Choose a reason for hiding this comment

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

nit: Extra space before 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

self._debugger_data_server.put_incoming_message(True)
# while True: # DEBUG
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of these debug comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

try:
self._debugger_data_server.stop_the_debugger_data_receiving_server()
except ValueError:
# In case the server has already stopped running.
pass
# break # DEBUG
self._server_thread.join()
print('InteractiveDebuggerPlugin stopped.')
sys.exit(0)

def get_plugin_apps(self):
"""Obtains a mapping between routes and handlers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ def start_the_debugger_data_receiving_server(self):
"""
self.run_server()

def stop_the_debugger_data_receiving_server(self):
self.stop_server()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this alias really necessary? The callsite could just call stop_server() directly, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Removed the stop_the_debugger_data_receiving_server and start_the_debugger_data_receiving_server methods.


def SendTracebacks(self, request, context):
self._source_manager.add_graph_traceback(request.graph_version,
request.graph_traceback)
Expand Down