Tensorboard: No python API for killing tensorboard process

Created on 14 Dec 2019  Â·  5Comments  Â·  Source: tensorflow/tensorboard

I don't think this one is environment related.
There's just simply no such thing as a exit API for python scripts, which means I have to use lsof + kill or quit the python parent process to kill the tensorboard.
I just feel like there should be a matching API for launch().

backend awaiting response feature

Most helpful comment

If I’m missing something and a separate kill function still sounds
necessary, could you please elaborate?

Of course this makes sense. However, I was trying to integrate the tensorboard launch and kill within a flask server as responses to certain request.

If the tensorboard can only be killed when the server is down, I wouldn't be able to handle multiple calls or I'll have to allow infinite ports.

Therefore, a separate kill function would be quite convenient.

All 5 comments

Hi @humancontext! We didn’t add an API to kill TensorBoard processes
because, as far as I know, there’s not really a good way to kill another
process on Windows. You can TerminateProcess, but that won’t shut
down the process gracefully, and so in particular future invocations of
%tensorboard or tensorboard.notebook.start will think that the
server is still running.

In principle, I suppose that we could include a kill API that works on
Unices and just isn’t implemented on Windows; we’d have to think about
whether this is something that we want to support.

From your mention of “lsof + kill”, it sounds like the API that you’re
looking for is along the lines of “kill the TensorBoard process running
on a given port” as opposed to “…with a given PID”. Is that correct?

Hi @wchargin . Thanks for replying.

it sounds like the API that you’re looking for is along the lines of “kill the TensorBoard process running on a given port” as opposed to “…with a given PID”. Is that correct?

Yes it's correct. Since the .launch API returns the url (with port included) instread of PID. I just think things would be good to be all paired up :D

Since the .launch API returns the url (with port included) instread of
PID

Oh, it sounds like you’re talking about tb.program.TensorBoard.launch?
That method launches a TensorBoard instance on a new daemon thread in
the same process. Thus, you can kill the enclosing TensorBoard instance
by simply exiting the Python program from which you called launch().

This is actually one of the intended purposes of program.TensorBoard:
to enable you to customize the process setup and teardown. For instance,
if you wanted a “TensorBoard that prints its port for easy killing”, you
could write:

import os
import time

import tensorboard


def main():
    tb = tensorboard.program.TensorBoard()
    tb.configure(bind_all=True, logdir="/tmp/logs")
    url = tb.launch()
    print("TensorBoard %s started at %s" % (tensorboard.__version__, url))
    pid = os.getpid()
    print("PID = %d; use 'kill %d' to quit" % (pid, pid))
    while True:
        try:
            time.sleep(60)
        except KeyboardInterrupt:
            break
    print()
    print("Shutting down")


if __name__ == "__main__":
    main()
$ python test.py 
TensorBoard 2.1.0a20191206 started at http://HOSTNAME:6006/
PID = 28779; use 'kill 28779' to quit
^C
Shutting down

This will properly shut down with either a Ctrl-C event at the terminal
or a kill signal sent to the listed process.

Does this make sense?

If I’m missing something and a separate kill function still sounds
necessary, could you please elaborate?

If I’m missing something and a separate kill function still sounds
necessary, could you please elaborate?

Of course this makes sense. However, I was trying to integrate the tensorboard launch and kill within a flask server as responses to certain request.

If the tensorboard can only be killed when the server is down, I wouldn't be able to handle multiple calls or I'll have to allow infinite ports.

Therefore, a separate kill function would be quite convenient.

I’m still not sure what you’re asking. Earlier you said that you wanted
to kill the process serving TensorBoard on a given port, but it sounds
like maybe you actually want to be able to gracefully shut down a
program.TensorBoard instance running in a larger program without
killing that program?

A Flask server can of course create and kill separate TensorBoard
processes without any special Python APIs, just by keeping references to
which PIDs it’s spawned.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KylePiira picture KylePiira  Â·  4Comments

Daniel451 picture Daniel451  Â·  3Comments

iron9light picture iron9light  Â·  4Comments

neouyghur picture neouyghur  Â·  3Comments

wengqi123 picture wengqi123  Â·  3Comments