3

I have a file script.py with code that opens a bokeh server like so:

def start_bokeh_server():
   subprocess.Popen(
       ["bokeh", "serve",
        "--show", "app.py",
        "--port", port,
        "--args", args])

In app.py, I would like to read in args.

In the documentation it says that it is possible to access the content of args inside the bokeh app with sys.argv. However, with using subprocess, sys.argv returns only the args to script.py, namely only the path to it.

Is it possible to view the args of the subprocess bokeh call inside the app?

Thanks a lot

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
katya_ava
  • 65
  • 1
  • 7
  • Here is the documentation to `bokeh serve`: https://docs.bokeh.org/en/latest/docs/reference/command/subcommands/serve.html – katya_ava Jul 30 '20 at 18:57
  • It seems like for non-bokeh scripts it worked... https://stackoverflow.com/questions/44661246/python-pass-sys-argv-when-loading-python-script-with-subprocess-popen, interesting – AlexNe Jul 30 '20 at 20:02
  • Could you please provide the code of `app.py`, or at least enough of it to let us reproduce the problem. – AlexNe Jul 30 '20 at 20:09

1 Answers1

3

Here is what I used as app.py just to read input arguments -

import sys

print(sys.argv)

Here is my script.py. I will pass the arguments to script.py from command line -

import subprocess
import sys

p = subprocess.Popen(["bokeh", "serve", "--show", "app.py", "--port", "5006", \
"--args", sys.argv[1], sys.argv[2], sys.argv[3]])

I called the script using python script.py t1 t2 t3, I am getting follwoing output -

2020-08-17 11:30:07,248 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2020-08-17 11:30:07,253 Bokeh app running at: http://localhost:5006/app
2020-08-17 11:30:07,253 Starting Bokeh server with process id: 78543
['app.py', 't1', 't2', 't3']

This clearly indicates, that I am able to read passed arguments inside app.py

Aritesh
  • 1,985
  • 1
  • 13
  • 17