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 -
the script hangs, and so does the flask web server.
Code Snippet -
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',
codec = CodecService()
provider1 = CodecServiceProvider(type="json")
print("past codec provider1")
crud = CRUDService()
print("past crud instantiation")
# Getting stuck below.
# Getting stuck at the above line
jsonIntPropObj = codec.encode(provider1, intPropObj1)
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.
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.
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?
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.