Failed to connect to the server

I try to run observe.py in IDLE.

/home/rafa/Desktop/gnuradio-compagnion/observe/observe.py’

Present on github.

File “/usr/local/lib/python2.7/dist-packages/bokeh/client/session.py”, line 369, in push
raise IOError(“Cannot push session document because we failed to connect
to the server (to start the server, try the ‘bokeh serve’ command)”)
IOError: Cannot push session document because we failed to connect to the server (to start the server, try the ‘bokeh serve’ command)

As you can see the issue is the connection with the server, but when i
try to connect typing in the ubuntu 16.04 terminal, bokeh serve, it works and when i try to plot a graph it works.

I can’t understand the issue there. i installed all dependencies and gr-bokehgui with the using source code.

Can you help me please ?

Thank you in advance .

In there the code observe.py:

#!/usr/bin/env python2

-- coding: utf-8 --

···

##################################################

GNU Radio Python Flow Graph

Title: Observe

Generated: Thu Apr 5 12:04:16 2018

##################################################

if name == ‘main’:
import ctypes
import sys
if sys.platform.startswith(‘linux’):
try:
x11 = ctypes.cdll.LoadLibrary(‘libX11.so’)
x11.XInitThreads()
except:
print “Warning: failed to XInitThreads()”

from bokeh.client import push_session
from bokeh.plotting import curdoc
from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import bokehgui
import functools
import signal
import time

class observe(gr.top_block):
def init(self, doc):
gr.top_block.init(self, “Observe”)
self.doc = doc
self.plot_lst =
self.widget_lst =

    ##################################################
    # Variables
    ##################################################
    self.samp_rate = samp_rate = 32000

    ##################################################
    # Blocks
    ##################################################
    self.bokehgui_time_sink_x_0 = bokehgui.time_sink_f_proc(1024, samp_rate, "", 1)
    self.bokehgui_time_sink_x_0_plot = bokehgui.time_sink_f(self.doc, self.plot_lst, self.bokehgui_time_sink_x_0, is_message = False)
   
    labels = ['', '', '', '', '',
              '', '', '', '', '']
    legend_list = []
    for i in xrange(1):
        if len(labels[i]) == 0:
            legend_list.append("Data {0}".format(i))
        else:
            legend_list.append(labels[i])
   
    self.bokehgui_time_sink_x_0_plot.initialize(log_x = False,
                               log_y = False,
                               update_time = 100,
                               legend_list = legend_list)
   
    self.bokehgui_time_sink_x_0_plot.set_y_axis([-1, 1])
    self.bokehgui_time_sink_x_0_plot.set_y_label('Amplitude')
    self.bokehgui_time_sink_x_0_plot.set_x_label('Time')
   
    self.bokehgui_time_sink_x_0_plot.enable_tags(-1, True)
    self.bokehgui_time_sink_x_0_plot.set_trigger_mode(bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
    self.bokehgui_time_sink_x_0_plot.enable_grid(False)
    self.bokehgui_time_sink_x_0_plot.enable_axis_labels(True)
    self.bokehgui_time_sink_x_0_plot.disable_legend(not True)
    self.bokehgui_time_sink_x_0_plot.set_layout(*(((1,0))))
   
    colors = ["blue", "red", "green", "black", "cyan",
              "magenta", "yellow", "blue", "blue", "blue"]
    widths = [1, 1, 1, 1, 1,
              1, 1, 1, 1, 1]
    styles = ["solid", "solid", "solid", "solid", "solid",
              "solid", "solid", "solid", "solid", "solid"]
    markers = [None, None, None, None, None,
               None, None, None, None, None]
    alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
              1.0, 1.0, 1.0, 1.0, 1.0]
    for i in xrange(1):
        self.bokehgui_time_sink_x_0_plot.format_line(i, colors[i], widths[i], styles[i], markers[i], alphas[i])
   
     
    self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
    self.blocks_add_xx_0 = blocks.add_vff(1)
    self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)
    self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, .01, 0)

    if self.widget_lst:
        input_t = bokehgui.BokehLayout.widgetbox(self.widget_lst)
        widgetbox = bokehgui.BokehLayout.WidgetLayout(input_t)
        widgetbox.set_layout(*((0, 0)))
        list_obj = [widgetbox] + self.plot_lst
    else:
        list_obj = self.plot_lst
    layout_t = bokehgui.BokehLayout.create_layout(list_obj, "fixed")
    self.doc.add_root(layout_t)

    ##################################################
    # Connections
    ##################################################
    self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))   
    self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0))   
    self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0))   
    self.connect((self.blocks_throttle_0, 0), (self.bokehgui_time_sink_x_0, 0))   

def get_samp_rate(self):
    return self.samp_rate

def set_samp_rate(self, samp_rate):
    self.samp_rate = samp_rate
    self.bokehgui_time_sink_x_0.set_samp_rate(self.samp_rate)
    self.blocks_throttle_0.set_sample_rate(self.samp_rate)
    self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)

def main(top_block_cls=observe, options=None):

 serverProc, port = bokehgui.utils.create_server()
 def killProc(signum, frame, tb):
     tb.stop()
     tb.wait()
     serverProc.terminate()
     serverProc.kill()
 time.sleep(1)
 try:
     # Define the document instance
     doc = curdoc()
     doc.title = "Observe"
     session = push_session(doc, session_id="observe",
                            url = "http://localhost:" + port + "/bokehgui")
     # Create Top Block instance
     tb = top_block_cls(doc)
     try:
         tb.start()
         signal.signal(signal.SIGTERM, functools.partial(killProc, tb=tb))
         session.loop_until_closed()
     finally:
         print "Exiting the simulation. Stopping Bokeh Server"
         tb.stop()
         tb.wait()
 finally:
     serverProc.terminate()
     serverProc.kill()

if name == ‘main’:
main()

Hi,

I'm not sure what specific advice I can offer, except to say that:

* a bokeh server, run using "bokeh serve" needs to be running somewhere accessible
* at the same time as your script executes, and
* the URL in the script needs to match where the server is concurrently running.

If you are getting this message, then one of those things is not true.

However, in general I would *very strongly* discourage you from using push_session and session_loop_until_closed in this way *at all*. The docs explicitly discourage trying to run Bokeh apps "outside" the server in this way:

It is possible to use bokeh.client to build up apps “from scratch”, outside a Bokeh server, including running and servicing callbacks by making a blocking call to session.loop_until_closed in the external Python process using bokeh.client. This usage has a number of inherent technical disadvantages, and should be considered unsupported.\'

Those disadvantages include:

* doubled network traffic / transport time
* some features (UI events) not supported in this mode and will never be
* needlessly fragile and complicated (requires multi-process coordination)

And more. Appropriate and useful and supported uses of bokeh.client, to connect to apps *running directly in a bokeh server*, are described here:

  Bokeh server — Bokeh 3.3.2 Documentation

Thanks,

Bryan

···

On Apr 5, 2018, at 14:50, Rafael Madeira <[email protected]> wrote:

I try to run observe.py in IDLE.

/home/rafa/Desktop/gnuradio-compagnion/observe/observe.py'

Present on github.

File "/usr/local/lib/python2.7/dist-packages/bokeh/client/session.py", line 369, in push
raise IOError("Cannot push session document because we failed to connect to the server (to start the server, try the 'bokeh serve' command)")
IOError: Cannot push session document because we failed to connect to the server (to start the server, try the 'bokeh serve' command)

As you can see the issue is the connection with the server, but when i try to connect typing in the ubuntu 16.04 terminal, bokeh serve, it works and when i try to plot a graph it works.

I can't understand the issue there. i installed all dependencies and gr-bokehgui with the using source code.

Can you help me please ?

Thank you in advance .

In there the code observe.py:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Observe
# Generated: Thu Apr 5 12:04:16 2018
##################################################

if __name__ == '__main__':
    import ctypes
    import sys
    if sys.platform.startswith('linux'):
        try:
            x11 = ctypes.cdll.LoadLibrary('libX11.so')
            x11.XInitThreads()
        except:
            print "Warning: failed to XInitThreads()"

from bokeh.client import push_session
from bokeh.plotting import curdoc
from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import bokehgui
import functools
import signal
import time

class observe(gr.top_block):
    def __init__(self, doc):
        gr.top_block.__init__(self, "Observe")
        self.doc = doc
        self.plot_lst =
        self.widget_lst =

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.bokehgui_time_sink_x_0 = bokehgui.time_sink_f_proc(1024, samp_rate, "", 1)
        self.bokehgui_time_sink_x_0_plot = bokehgui.time_sink_f(self.doc, self.plot_lst, self.bokehgui_time_sink_x_0, is_message = False)
        
        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        legend_list =
        for i in xrange(1):
            if len(labels[i]) == 0:
                legend_list.append("Data {0}".format(i))
            else:
                legend_list.append(labels[i])
        
        self.bokehgui_time_sink_x_0_plot.initialize(log_x = False,
                                   log_y = False,
                                   update_time = 100,
                                   legend_list = legend_list)
        
        self.bokehgui_time_sink_x_0_plot.set_y_axis([-1, 1])
        self.bokehgui_time_sink_x_0_plot.set_y_label('Amplitude')
        self.bokehgui_time_sink_x_0_plot.set_x_label('Time')
        
        self.bokehgui_time_sink_x_0_plot.enable_tags(-1, True)
        self.bokehgui_time_sink_x_0_plot.set_trigger_mode(bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.bokehgui_time_sink_x_0_plot.enable_grid(False)
        self.bokehgui_time_sink_x_0_plot.enable_axis_labels(True)
        self.bokehgui_time_sink_x_0_plot.disable_legend(not True)
        self.bokehgui_time_sink_x_0_plot.set_layout(*(((1,0))))
        
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "blue", "blue", "blue"]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        styles = ["solid", "solid", "solid", "solid", "solid",
                  "solid", "solid", "solid", "solid", "solid"]
        markers = [None, None, None, None, None,
                   None, None, None, None, None]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            self.bokehgui_time_sink_x_0_plot.format_line(i, colors[i], widths[i], styles[i], markers[i], alphas[i])
        
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, .01, 0)

        if self.widget_lst:
            input_t = bokehgui.BokehLayout.widgetbox(self.widget_lst)
            widgetbox = bokehgui.BokehLayout.WidgetLayout(input_t)
            widgetbox.set_layout(*((0, 0)))
            list_obj = [widgetbox] + self.plot_lst
        else:
            list_obj = self.plot_lst
        layout_t = bokehgui.BokehLayout.create_layout(list_obj, "fixed")
        self.doc.add_root(layout_t)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.bokehgui_time_sink_x_0, 0))

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.bokehgui_time_sink_x_0.set_samp_rate(self.samp_rate)
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
        self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)

def main(top_block_cls=observe, options=None):

     serverProc, port = bokehgui.utils.create_server()
     def killProc(signum, frame, tb):
         tb.stop()
         tb.wait()
         serverProc.terminate()
         serverProc.kill()
     time.sleep(1)
     try:
         # Define the document instance
         doc = curdoc()
         doc.title = "Observe"
         session = push_session(doc, session_id="observe",
                                url = "http://localhost:" + port + "/bokehgui")
         # Create Top Block instance
         tb = top_block_cls(doc)
         try:
             tb.start()
             signal.signal(signal.SIGTERM, functools.partial(killProc, tb=tb))
             session.loop_until_closed()
         finally:
             print "Exiting the simulation. Stopping Bokeh Server"
             tb.stop()
             tb.wait()
     finally:
         serverProc.terminate()
         serverProc.kill()

if __name__ == '__main__':
    main()

--
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/6163025c-ba4b-41b0-920e-9bd82bd76d33%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.