-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the backend work inside a Docker container #11
base: master
Are you sure you want to change the base?
Conversation
|
||
with BytesIO() as buf: | ||
self.canvas.figure.savefig(buf, format='png', facecolor='#888888') | ||
icat('--align', 'left', output=False, input=buf.getbuffer()) | ||
write_chunked(a='T', f=100, data=buf.getvalue()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was getting the following error with getbuffer()
:
BufferError: Existing exports of data: object cannot be re-sized
Reproducible example:
import io
with io.BytesIO() as buf:
buf.write(b'hello')
res = buf.getbuffer()
You dont need to use an escape code to get the size, use the example code from the graphics protocol docs: import array, fcntl, sys, termios
buf = array.array('H', [0, 0, 0, 0])
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
print((
'number of rows: {} number of columns: {}'
'screen width: {} screen height: {}').format(*buf)) This code is what icat uses as well, so if icat worked so will this. |
Thanks for the feedback and the amazing terminal emulator @kovidgoyal. The recipe didn't quite work for me inside a Docker container sadly. It manages to get rows and columns just right but the height and width in pixels are both zeros despite me having specified |
On Fri, Aug 25, 2023 at 01:26:39AM -0700, ayorgo wrote:
Thanks for the feedback @kovidgoyal. The recipe didn't quite work for me inside a Docker container sadly. It manages to get rows and columns just right but the height and width in pixels are both zeros despite me having specified `-e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix` as well as `-v /usr/lib/kitty/terminfo/x:/root/.terminfo/x` although I'm not particularly happy with forcing people to install `kitty` itself inside containers. The escape code on the other hand works quite well both inside and outside of a container.
SSH into your container and it will work. I am guessing that the
container runtime's PTY implementation does not fill in the pixel fields
of the wininfo struct.
Note you dont need to install kitty inside the container, all you need
is the kitten standalone executable which is available as a statically
compiled binary for all unix like operating systems. Again if you SSH
into your container using the ssh kitten it will actually be
automatically made available inside the container no need to even
install that single binary file.
|
Fair enough although that requires some extra steps like opening the ssh port, having the ssh server installed and configured inside the container, a firewall properly setup, then running the While technically viable I'd argue that it isn't the simplest solution for a lay person like e.g. myself (and some of my data science colleagues as well) whereas the proposed solution with the escape code while a bit cumbersome to implement works straight away without any extra steps. |
Well, the correct solution is of course, to get docker to fill in the winsize struct properly in their pseudo terminal implementation. Then you wont have to jump through these hoops. In the meantime, I suggest using the ioctl first and falling back to the escape code only if it returns zero. That way people not running inside docker dont pay the price. |
Makes perfect sense. I'll look into how to pass pixel dimensions to a container. Just curious, what do you mean by "pay the price"? Is the escape code method slower than the one with |
Yes, much slower. Escape code means the kernel has to send the escape code from your program to the terminal over a tty device, the terminal has to parse it and then the kernel has to send the terminals reply to your program again over a tty device, which then has to parse that reply. And say the user is running this program over SSH then there is basically unbounded latency depending on the speed and quality of the network link. By contrast the ioctl() is a single context switch into the kernel which copies the cached winsize struct into your programs memory. |
919f6ff
to
349e776
Compare
|
||
# account for post-display prompt scrolling | ||
# 3 line shift for [\n, <matplotlib.axes…, >>>] after the figure | ||
px[1] -= int(3*(px[1]/rows)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't really see the point of the post-display prompt scrolling. Can change it back if the maintainers insist.
This addresses #10 by using
kitty
's low level graphics protocol.The main challenge was to get the window dimensions in pixels as described here which was solved with the help of this SO answer.