05-02-2019 08:41 AM
Hello Experts,
I'd like some guidance on a script that gets operational data from xr router, then certain key/values are extracted from the json output, with the goal to display it on a webpage (using YDK-PY with FLASK microframework to display data on to the webpage.
when I call the flask app.router(/interfaceStats) decorater, my script seems to hang at the CRUD operation. During the crud -
intPropObj1=crud.read(provider, intPropObj)
the script hangs, and so does the flask web server.
Regards,
RK
Code Snippet -
@app.route('/interfaceStats')
def interfaceStats():
_init_logging()
dir_path = os.path.dirname(os.path.realpath(__file__))
private = "%s/id_rsa" % dir_path
public = "%s/id_rsa.pub" % dir_path
print(dir_path, private, public)
provider = NetconfServiceProvider(address='192.168.253.144',
username='rkotwani',
protocol='ssh',
timeout=0,
port=22,
private_key_path=private,
public_key_path=public)
codec = CodecService()
provider1 = CodecServiceProvider(type="json")
print("past codec provider1")
crud = CRUDService()
print("past crud instantiation")
intPropObj=ifmgr_oper.InterfaceProperties()
print("here")
# Getting stuck below.
intPropObj1=crud.read(provider, intPropObj)
# Getting stuck at the above line
print("here 2")
jsonIntPropObj = codec.encode(provider1, intPropObj1)
print(jsonIntPropObj)
return render_template('index.html')
05-30-2019 03:56 PM
were you able to sort out the problem?
11-16-2020 10:56 PM
Hello,
Does anybody have an idea about this? we have the totally same issue with this.
The crudService.read ran well when we use single python script, but got stuck when it in the flask framework which as a http service.
please help me, thanks very much.
11-17-2020 10:10 AM
Hello Elvis Lou
In my opinion you are facing known and documented issue, which is related to multithreading. I believe the flask operator, spawns new thread, which interrupts thread with YDK related process. As a workaround you have to refactor structure of your script in a way that WHOLE YDK related operation is inclosed in one thread from start to finish.
11-17-2020 04:23 PM
Thanks for the reply, yangorelik,
so it is not possible that run ydk api call concurrently in one process?
is it must ran Serializable for any operation to cisco router?
11-18-2020 10:33 AM
You can have multiple threads in one process, but when it comes to execution of YDK involved operation, the last must be located in single thread.
The issue #825 has nothing to do with serialization, it comes from YDK design/implementation. Keep in mind that all actual operations on data is happening in C++ code, which is connected to Python code via Pybind11 adapter. When Python code sends request to C++ code the adapter locks the python thread in order to get reliably the response.
In your script example you import YDK related modules and initiate logger in main thread. The Flask call creates another thread to execute interfaceStats() function. That action confuses Pybind11 adapter and eventually causes the YDK thread to get stalled.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide