User input through Torizon - Application Container Output

Hi,

I 'm deploying a Python application to a Verdin IMX8MM using the VSC extension and I want to get some user input from the command line as part of the application but the input() function throws the EOFError exception. When I SSH to the host, enter the container and run the application it works fine. Is there a way to get it to work in VSC as well? I think this is because stdin is being redirected to a file instead of the terminal but I can’t figure out if there is a setting to fix it.

Thanks

Ed

Hi @edwaugh,

When we debug a Python (or C/C++) application with Torizon Extension, the console I/O is processed by the debugger and stdin is not accessible by default, and we don’t redirect it through docker.

Our suggestion is for you to read info from a regular file instead or, if you have a menu or something like this, expose it via socket for the testing.

Best regards,
André Curvello

Thanks Andre, I will take a look at the socket idea. Any suggestions very welcome.

Ok!

And, please, let us know if you managed to debug it, even using socket.

Best regards,
André Curvello

Hi Andre,

I did make this work and have written a python class to act as a debug socket. If anyone needs it just let me know and I can share.

Ed

Hi @edwaugh,

That is really interesting!

Can you share with us?

@valter.tx what do you think about it?

Best regards,
André Curvello

If it’s something you can share that would be great to improve usability.

Hi @valter.tx and @andrecurvello.tx,

I have attached here, it should work for Windows or Linux but I have not tried on Windows for a while. It has been working ok for me in debug mode on Torizon. Of course you don’t really need it in release builds as I can just attach to the running container from SSH but it does still work as well.

Usage should just be:

dss = DebugSocket()
dss.start()
dss.clear_screen()
dss.register_connection_callback('print_menu', menu.print_menu)    
dss.register_disconnection_callback('print_menu', menu.print_menu)

The print menu function I pass just prints some text. Socket will redirect stdio for you once someone connects on a raw 65432 port. And will return control when they disconnect. Only remaining todo is to add a timeout to detect a badly behaved disconnection. At the moment it just waits for ever.

Thanks

Ed

debug_socket_select.zip

Thanks for sharing the files.