· Sep 7, 2023 2m read

Using Embedded Python in WebTerminal

In a previous question, I have illustrated a few problems using Embedded Python
interactively as you would do from Docker console or IRIS terminal.
Investigation of the causes brought a rather clear picture. It's a classic impedance mismatch

  • While consoles act rather relaxed WebTerminal is very precise in output presentation line terminators from (Embedded) Python's print() function are typically <LF>  0x0A  $C(10) And WebTerminal does exactly this while eg. my console in Docker also does a <CR> und cover. So a sequence of print() looks like a scale
  • Compared to ObjectScript where a WRTE !  sends <CR><LF>  $C(13,10) and WebTeminal is happy. So a sequence of lines looks like a tower of text. This is not a serious problem more embarrassing.
  • User input from the console is a more serious problem. WebTerminal presents his actual device as some /nul  and uses device redirection for passing values.  Embedded Python interprets this as immediate Empty String input. If you have appropriate defaults you go along.  But if you expect some STOP signal from the user you are lost in an endless loop.

So I have created this workaround:

  • A wrapper starts my Embedded Python ONLY and establishes an internal TCP channel as a background job.
  • By this, my Python code sees some Non-NUL device similar to a terminal or console and acts without change.
  • The wrapper acts as the front end
    • to take care of normal-looking output adding <CR> %C(13) to simple >LF> $C(10)
    • takes care of proper prompted input  

And now my package in Online Deme looks more attractive:

Discussion (1)1
Log in or sign up to continue