Bokeh catches python logging and print

I’m working on a microservice that employs bokeh, and I’m running into a problem. I’m running it in a custom system that employs a Kafka bus and docker containers, but I do have the normal terminal output.

When I run my code using bokeh serve, it works, and shows a graph. But I’m not seeing any output from print() or from logging (which also prints to terminal). Bokeh itself seems to be able to print to the terminal just fine.

My question is: is it possible to get Bokey to allow Python to output print() and such to the terminal?

Hi,

I don't really understand the situation are describing. Do you mean printing to the console from e.g. Bokeh callbacks? I do that all the time, and there is never any issue. In order to help we would really need more information and a minimal example to reproduce.

Thanks.

Bryan

···

On Feb 11, 2019, at 08:05, [email protected] wrote:

I'm working on a microservice that employs bokeh, and I'm running into a problem. I'm running it in a custom system that employs a Kafka bus and docker containers, but I do have the normal terminal output.

When I run my code using bokeh serve, it works, and shows a graph. But I'm not seeing any output from print() or from logging (which also prints to terminal). Bokeh itself seems to be able to print to the terminal just fine.

My question is: is it possible to get Bokey to allow Python to output print() and such to the terminal?

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/aac79404-f15f-4b66-99e6-18c078dbe780%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

The Bokeh callbacks are printing properly, but I’ve got a need for some feedback from the python script.

If I run ‘bokeh serve’ on a python script ‘myfunc.py’, and the latter contains:

print(‘hi’)

``

I will not see ‘hi’ in my terminal. I see Bokeh giving proper feedback and everything, but I suspect it’s catching the writes to stdout from the python script. Unfortunately, that makes it very difficult to debug this script.

···

On Monday, February 11, 2019 at 5:23:39 PM UTC+1, Bryan Van de ven wrote:

Hi,

I don’t really understand the situation are describing. Do you mean printing to the console from e.g. Bokeh callbacks? I do that all the time, and there is never any issue. In order to help we would really need more information and a minimal example to reproduce.

Thanks.

Bryan

On Feb 11, 2019, at 08:05, [email protected] wrote:

I’m working on a microservice that employs bokeh, and I’m running into a problem. I’m running it in a custom system that employs a Kafka bus and docker containers, but I do have the normal terminal output.

When I run my code using bokeh serve, it works, and shows a graph. But I’m not seeing any output from print() or from logging (which also prints to terminal). Bokeh itself seems to be able to print to the terminal just fine.

My question is: is it possible to get Bokey to allow Python to output print() and such to the terminal?


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/aac79404-f15f-4b66-99e6-18c078dbe780%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

This is possibly a common misconception. The code in the script is run every time a session is opened. I.e. every time a user navigates to the URL and a connection is made from a browser, all the code in the script is run, in order to generate a fresh, unique collection of Bokeh models to service that particular session. However, the converse is also true: the script code is never run, unless and until a connection is made. So if you want to see "top level" print statements in the app script, you will have to open a session first.

Thanks,

Bryan

···

On Feb 12, 2019, at 01:48, [email protected] wrote:

The Bokeh callbacks are printing properly, but I've got a need for some feedback from the python script.

If I run 'bokeh serve' on a python script 'myfunc.py', and the latter contains:
print('hi')
I will not see 'hi' in my terminal. I see Bokeh giving proper feedback and everything, but I suspect it's catching the writes to stdout from the python script. Unfortunately, that makes it very difficult to debug this script.

On Monday, February 11, 2019 at 5:23:39 PM UTC+1, Bryan Van de ven wrote:
Hi,

I don't really understand the situation are describing. Do you mean printing to the console from e.g. Bokeh callbacks? I do that all the time, and there is never any issue. In order to help we would really need more information and a minimal example to reproduce.

Thanks.

Bryan

> On Feb 11, 2019, at 08:05, [email protected] wrote:
>
> I'm working on a microservice that employs bokeh, and I'm running into a problem. I'm running it in a custom system that employs a Kafka bus and docker containers, but I do have the normal terminal output.
>
> When I run my code using bokeh serve, it works, and shows a graph. But I'm not seeing any output from print() or from logging (which also prints to terminal). Bokeh itself seems to be able to print to the terminal just fine.
>
> My question is: is it possible to get Bokey to allow Python to output print() and such to the terminal?
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/aac79404-f15f-4b66-99e6-18c078dbe780%40continuum.io.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/a1b5dbad-814c-4d1b-8bc1-3fe1da2b2bcd%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

It did take me longer than I'd like to admit to realize that the script is only called after a user requests the page, but I'm not sure that is the case. If I request the page, I do see the graph, and bokeh reports (through the terminal) that it's made a connection. So the script is running, but I'm still not seeing the result of the print() commands in the terminal. If I put a deliberate error in the script, I do get proper python output telling me what went wrong, but I'm just not seeing the normal print() and logging output.

Hi, it’s definitely working as expected for me:

So at this point it’s not really possible to speculate about your particular situation without a minimal, complete, reproducer.

Thanks,

Bryan

···

On Feb 12, 2019, at 10:23, [email protected] wrote:

It did take me longer than I’d like to admit to realize that the script is only called after a user requests the page, but I’m not sure that is the case. If I request the page, I do see the graph, and bokeh reports (through the terminal) that it’s made a connection. So the script is running, but I’m still not seeing the result of the print() commands in the terminal. If I put a deliberate error in the script, I do get proper python output telling me what went wrong, but I’m just not seeing the normal print() and logging output.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/acbc565e-0721-497c-9a41-71212764319a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

If I simply adapt an existing example
import random

from bokeh.driving import linear

from bokeh.plotting import figure, curdoc

print(‘test’)

p = figure(plot_width=400, plot_height=400)

r1 = p.line(, , color=“firebrick”, line_width=2)

r2 = p.line(, , color=“navy”, line_width=2)

ds1 = r1.data_source

ds2 = r2.data_source

@linear()

def update(step):

ds1.data['x'].append(step)

ds1.data['y'].append(random.randint(0, 100))

ds2.data['x'].append(step)

ds2.data['y'].append(random.randint(0, 100))

ds1.trigger('data', ds1.data, ds1.data)

ds2.trigger('data', ds2.data, ds2.data)

curdoc().add_root§

curdoc().add_periodic_callback(update, 100)

``

and then run this with:

bokeh serve --show example.py

``

I do not see the ‘test’ message, at all. I do see the Bokeh feedback. But I’m starting to suspect my situation is a bit unique, which may account for the lack of some output. This goes into a docker container, which is then ran in a custom cloud-based solution with extra layers of security and such, and a custom terminal-like phenomenon that catches the output from the container.

This may mean I need to change my question; is there a way to add custom messages to the Bokeh output?

···

On Tuesday, February 12, 2019 at 7:32:54 PM UTC+1, Bryan Van de ven wrote:

Hi, it’s definitely working as expected for me:

So at this point it’s not really possible to speculate about your particular situation without a minimal, complete, reproducer.

Thanks,

Bryan

On Feb 12, 2019, at 10:23, [email protected] wrote:

It did take me longer than I’d like to admit to realize that the script is only called after a user requests the page, but I’m not sure that is the case. If I request the page, I do see the graph, and bokeh reports (through the terminal) that it’s made a connection. So the script is running, but I’m still not seeing the result of the print() commands in the terminal. If I put a deliberate error in the script, I do get proper python output telling me what went wrong, but I’m just not seeing the normal print() and logging output.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/acbc565e-0721-497c-9a41-71212764319a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Casper,

I think this happens because you run your code inside a Docker container.

When I run “python example.py” in Eclipse Che which also runs in a Docker container the printing works but it doesn’t using “bokeh serve —show example.py”. Also the browser window doesn’t open.

The last command involves tornado and the socket communication inside the container probably runs into port-mapping issues.

Could you share your Dockerfile?

Please note that a Docker container can communicate with the outside word but it is not the truth the other way around.

Maybe this post can help you…

···

On Wednesday, February 13, 2019 at 10:18:15 AM UTC+1, Casper van Heck wrote:

If I simply adapt an existing example
import random

from bokeh.driving import linear

from bokeh.plotting import figure, curdoc

print(‘test’)

p = figure(plot_width=400, plot_height=400)

r1 = p.line(, , color=“firebrick”, line_width=2)

r2 = p.line(, , color=“navy”, line_width=2)

ds1 = r1.data_source

ds2 = r2.data_source

@linear()

def update(step):

ds1.data['x'].append(step)
ds1.data['y'].append(random.randint(0, 100))
ds2.data['x'].append(step)
ds2.data['y'].append(random.randint(0, 100))
ds1.trigger('data', ds1.data, ds1.data)
ds2.trigger('data', ds2.data, ds2.data)

curdoc().add_root§

curdoc().add_periodic_callback(update, 100)

``

and then run this with:

bokeh serve --show example.py

``

I do not see the ‘test’ message, at all. I do see the Bokeh feedback. But I’m starting to suspect my situation is a bit unique, which may account for the lack of some output. This goes into a docker container, which is then ran in a custom cloud-based solution with extra layers of security and such, and a custom terminal-like phenomenon that catches the output from the container.

This may mean I need to change my question; is there a way to add custom messages to the Bokeh output?

On Tuesday, February 12, 2019 at 7:32:54 PM UTC+1, Bryan Van de ven wrote:

Hi, it’s definitely working as expected for me:

So at this point it’s not really possible to speculate about your particular situation without a minimal, complete, reproducer.

Thanks,

Bryan

On Feb 12, 2019, at 10:23, [email protected] wrote:

It did take me longer than I’d like to admit to realize that the script is only called after a user requests the page, but I’m not sure that is the case. If I request the page, I do see the graph, and bokeh reports (through the terminal) that it’s made a connection. So the script is running, but I’m still not seeing the result of the print() commands in the terminal. If I put a deliberate error in the script, I do get proper python output telling me what went wrong, but I’m just not seeing the normal print() and logging output.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/acbc565e-0721-497c-9a41-71212764319a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

When I modify your code like below the printing works but it is not the recommended way of running Bokeh server (see warnings in the terminal).
Start the Bokeh server first in one terminal with “bokeh serve” then run the code below in second terminal as “python test_printing.py”

import random
from bokeh.driving import linear
from bokeh.plotting import figure, curdoc
from bokeh.client import push_session
from datetime import datetime

print(‘test’)

session = push_session(document = curdoc())
print (datetime.now().strftime("%H:%M:%S:"), “Connecting to Bokeh server application at: http://localhost:5006/?bokeh-session-id=%s” % session.id)

p = figure(plot_width=400, plot_height=400)
r1 = p.line(, , color=“firebrick”, line_width=2)
r2 = p.line(, , color=“navy”, line_width=2)

ds1 = r1.data_source
ds2 = r2.data_source

@linear()
def update(step):
ds1.data[‘x’].append(step)
ds1.data[‘y’].append(random.randint(0, 100))
ds2.data[‘x’].append(step)
ds2.data[‘y’].append(random.randint(0, 100))
ds1.trigger(‘data’, ds1.data, ds1.data)
ds2.trigger(‘data’, ds2.data, ds2.data)

curdoc().add_root§
curdoc().add_periodic_callback(update, 1000)
session.loop_until_closed()

``

···

On Wednesday, February 13, 2019 at 10:18:15 AM UTC+1, Casper van Heck wrote:

If I simply adapt an existing example
import random

from bokeh.driving import linear

from bokeh.plotting import figure, curdoc

print(‘test’)

p = figure(plot_width=400, plot_height=400)

r1 = p.line(, , color=“firebrick”, line_width=2)

r2 = p.line(, , color=“navy”, line_width=2)

ds1 = r1.data_source

ds2 = r2.data_source

@linear()

def update(step):

ds1.data['x'].append(step)
ds1.data['y'].append(random.randint(0, 100))
ds2.data['x'].append(step)
ds2.data['y'].append(random.randint(0, 100))
ds1.trigger('data', ds1.data, ds1.data)
ds2.trigger('data', ds2.data, ds2.data)

curdoc().add_root§

curdoc().add_periodic_callback(update, 100)

``

and then run this with:

bokeh serve --show example.py

``

I do not see the ‘test’ message, at all. I do see the Bokeh feedback. But I’m starting to suspect my situation is a bit unique, which may account for the lack of some output. This goes into a docker container, which is then ran in a custom cloud-based solution with extra layers of security and such, and a custom terminal-like phenomenon that catches the output from the container.

This may mean I need to change my question; is there a way to add custom messages to the Bokeh output?

On Tuesday, February 12, 2019 at 7:32:54 PM UTC+1, Bryan Van de ven wrote:

Hi, it’s definitely working as expected for me:

So at this point it’s not really possible to speculate about your particular situation without a minimal, complete, reproducer.

Thanks,

Bryan

On Feb 12, 2019, at 10:23, [email protected] wrote:

It did take me longer than I’d like to admit to realize that the script is only called after a user requests the page, but I’m not sure that is the case. If I request the page, I do see the graph, and bokeh reports (through the terminal) that it’s made a connection. So the script is running, but I’m still not seeing the result of the print() commands in the terminal. If I put a deliberate error in the script, I do get proper python output telling me what went wrong, but I’m just not seeing the normal print() and logging output.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/acbc565e-0721-497c-9a41-71212764319a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Bokeh uses log statements

  import logging
  log = logging.getLogger(__name_)
  log.info(...)

Bokeh also does some logger configuration of its own on import, mostly to try to make sure that deprecation warnings are not silenced nay default. I doubt that has any effect, but for completeness you can see what we do here:

  https://github.com/bokeh/bokeh/blob/master/bokeh/util/logconfig.py

Thanks,

Bryan

···

On Feb 13, 2019, at 01:18, [email protected] wrote:

If I simply adapt an existing example
import random
from bokeh.driving import linear
from bokeh.plotting import figure, curdoc

print('test')

p = figure(plot_width=400, plot_height=400)
r1 = p.line(, , color="firebrick", line_width=2)
r2 = p.line(, , color="navy", line_width=2)

ds1 = r1.data_source
ds2 = r2.data_source

@linear()
def update(step):
    ds1.data['x'].append(step)
    ds1.data['y'].append(random.randint(0, 100))
    ds2.data['x'].append(step)
    ds2.data['y'].append(random.randint(0, 100))
    ds1.trigger('data', ds1.data, ds1.data)
    ds2.trigger('data', ds2.data, ds2.data)

curdoc().add_root(p)

curdoc().add_periodic_callback(update, 100)

and then run this with:
bokeh serve --show example.py

I do not see the 'test' message, at all. I do see the Bokeh feedback. But I'm starting to suspect my situation is a bit unique, which may account for the lack of some output. This goes into a docker container, which is then ran in a custom cloud-based solution with extra layers of security and such, and a custom terminal-like phenomenon that catches the output from the container.

This may mean I need to change my question; is there a way to add custom messages to the Bokeh output?

On Tuesday, February 12, 2019 at 7:32:54 PM UTC+1, Bryan Van de ven wrote:
Hi, it's definitely working as expected for me:

So at this point it's not really possible to speculate about your particular situation without a minimal, complete, reproducer.

Thanks,

Bryan

On Feb 12, 2019, at 10:23, [email protected] wrote:

It did take me longer than I'd like to admit to realize that the script is only called after a user requests the page, but I'm not sure that is the case. If I request the page, I do see the graph, and bokeh reports (through the terminal) that it's made a connection. So the script is running, but I'm still not seeing the result of the print() commands in the terminal. If I put a deliberate error in the script, I do get proper python output telling me what went wrong, but I'm just not seeing the normal print() and logging output.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/acbc565e-0721-497c-9a41-71212764319a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0592c112-eb35-4835-aa82-f749d99ef00a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I managed to connect to the Bokeh logging handle, and am now able to get custom messages! Thanks!

···

On Wednesday, February 13, 2019 at 5:19:24 PM UTC+1, Bryan Van de ven wrote:

Bokeh uses log statements

    import logging

    log = logging.getLogger(__name_)

    [log.info](http://log.info)(...)

Bokeh also does some logger configuration of its own on import, mostly to try to make sure that deprecation warnings are not silenced nay default. I doubt that has any effect, but for completeness you can see what we do here:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/util/logconfig.py](https://github.com/bokeh/bokeh/blob/master/bokeh/util/logconfig.py)

Thanks,

Bryan

On Feb 13, 2019, at 01:18, [email protected] wrote:

If I simply adapt an existing example

import random

from bokeh.driving import linear

from bokeh.plotting import figure, curdoc

print(‘test’)

p = figure(plot_width=400, plot_height=400)

r1 = p.line(, , color=“firebrick”, line_width=2)

r2 = p.line(, , color=“navy”, line_width=2)

ds1 = r1.data_source

ds2 = r2.data_source

@linear()

def update(step):

ds1.data['x'].append(step)
ds1.data['y'].append(random.randint(0, 100))
ds2.data['x'].append(step)
ds2.data['y'].append(random.randint(0, 100))
ds1.trigger('data', ds1.data, ds1.data)
ds2.trigger('data', ds2.data, ds2.data)

curdoc().add_root§

curdoc().add_periodic_callback(update, 100)

and then run this with:

bokeh serve --show example.py

I do not see the ‘test’ message, at all. I do see the Bokeh feedback. But I’m starting to suspect my situation is a bit unique, which may account for the lack of some output. This goes into a docker container, which is then ran in a custom cloud-based solution with extra layers of security and such, and a custom terminal-like phenomenon that catches the output from the container.

This may mean I need to change my question; is there a way to add custom messages to the Bokeh output?

On Tuesday, February 12, 2019 at 7:32:54 PM UTC+1, Bryan Van de ven wrote:

Hi, it’s definitely working as expected for me:

So at this point it’s not really possible to speculate about your particular situation without a minimal, complete, reproducer.

Thanks,

Bryan

On Feb 12, 2019, at 10:23, [email protected] wrote:

It did take me longer than I’d like to admit to realize that the script is only called after a user requests the page, but I’m not sure that is the case. If I request the page, I do see the graph, and bokeh reports (through the terminal) that it’s made a connection. So the script is running, but I’m still not seeing the result of the print() commands in the terminal. If I put a deliberate error in the script, I do get proper python output telling me what went wrong, but I’m just not seeing the normal print() and logging output.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/acbc565e-0721-497c-9a41-71212764319a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0592c112-eb35-4835-aa82-f749d99ef00a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Can you please describe your method of attaching to the bokeh logging handle? I am using docker-compose to start a bokeh server using ‘bokeh serve’. To get get log output using docker-compose I would normally run a python script with a ‘-u’ argument but this is impossible with ‘bokeh serve’ and I can’t figure out how to grab the bokeh logging handle. Thanks

@2xmm You can also use invoke the bokeh command with python -m

python -m bokeh serve  ...

presumably you can add -u to the initial python

Thanks.

Just looking at this again I tried the following and it worked with docker-compose. Need to attach to the ‘bokeh’ handler as follows:

log = logging.getLogger('bokeh')
log.info('Message...')

For reference this is my docker-compose setup for bokeh:

version: "3"
services:
    plotter:
        build:
            context: .
            dockerfile: ./plotter/Dockerfile
        command: bokeh serve ./app
        ports: 
        - "5006:5006"
        stdin_open: true
        tty: true