Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to access the args given to it when running a bokeh server by a subprocess?

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

like image 774
katya_ava Avatar asked Jan 20 '26 20:01

katya_ava


1 Answers

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

like image 177
Aritesh Avatar answered Jan 23 '26 09:01

Aritesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!