Hi everyone, first I’d like to say a massive thanks to everyone at Anvil for making this tool available, and to everyone on these forums for your answers to other questions, as they have been a massive help over the last few months. While I’m not completely new to coding I’m by no means fantastic at it so this may be a simple fix, but it has me at a loss!
I’ve encountered a bit of a weird issue. I’m running my app using the server app on a Raspberry Pi (as I only need it accessible off the local network). I previously had it installed and working on a system using Python 2.7 as the default, however I wanted to change it over to Python 3 as Python 2 is now unsupported. Having installed all the required libraries again (which provided a valuable lesson in the need for some kind of documentation as you go!) I’ve got myself to a point where the app loads up. The basic point of this part of the app is to take two photos with webcams and then display the images on the screen so the user can see them. While the image content changes over time they always have the same file names.
Now here comes the bit that has me stumped. Previously I was able to save and load the images from my _/theme/assets/ folder to display in the app using the simple anvil.media.from_file command. Since I’ve moved across to Python 3 this is no longer working with some .jpg files. Any time the server module tries to run the the command for some image files it returns the following error in the command line:
“EOFError while reading worker stdout. This should not have happened.
Server code exited unexpectedly: dad065712e (IDs client-CYWZieXGMVgQJ1fpv5HWBw==)”
I’ve included the relevant snippets of both the client and server side code below to show how the code is currently written.
From my basic checking it seems to be an issue around ‘larger’ files. In this case both leftPreview.jpg and rightPreview.jpg are just over 1MB, while recordSymbol.jpg is only 11kB. When run with recordSymbol.jpg as the file to be returned then type(text) returns <class ‘anvil.BlobMedia’> as you would expect.
Fortunately while trying to figure this out I had a spare microSD hanging around, so I installed a clean copy of Raspberry Pi OS on that and set everything up with Python 2 still as the default and it runs as expected (displaying the larger images from file, and from fresh camera captures) so I’m 95% sure that my issue lies with some difference between Python 2 & 3 rather than some difference in the versions of Anvil between my old setup and new.
I’ve tried setting the image source attribute to the file’s locations, however this just displays an empty space. I’ve also stopped the cameras from taking images and just left the two preview images as fixed assets and the error message still occurs.
Any help or suggestions would be gratefully received!
Client Code
print("[INFO]... Capturing Left Preview")
test = anvil.server.call('previewImgCap', 0)
print("[INFO]... Test object type:")
print(type(test))
self.cam_left_preview.source = test
print("[INFO]... Capturing Right Preview")
anvil.server.call('previewImgCap', 1)
self.cam_right_preview.source = anvil.server.call('previewImgCap', 1)
Server Code
@anvil.server.callable
def previewImgCap(camNum=0):
themeLoc = "/home/pi/LaxCam/theme/assets/"
if camNum is 0:
# Return preview image as media object to client code
print("[INFO]... Left Preview Taken.")
leftFile = anvil.media.from_file(themeLoc + 'leftPreview.jpg', 'image/jpeg')
#leftFile = anvil.media.from_file(themeLoc + 'recordSymbol.jpg', 'image/jpeg')
return leftFile
else:
preview_image_code.rightCap()
return anvil.media.from_file(themeLoc + 'rightPreview.jpg', 'image/jpeg')
#return anvil.media.from_file(themeLoc + 'recordSymbol.jpg', 'image/jpeg')