0

I encountered the following error message while running a python script that I am working on. It occurred while tkinter was loading ~1800 thumbnail images, each being 200x200 pixels large, into individual ttk.Checkkbuttons. It did not finish this process and the program crashed with this error message.

X Error of failed request: BadAlloc (insufficient resources for operation) Major opcode of failed request: 53 (X_CreatePixmap) Serial number of failed request: 140089 Current serial number in output stream: 140097 

The system that I ran this python tkinter script has a large RAM capacity. Before the program crashed, the RAM utilisation was only around 10%.

I don't understand this error message. Can you please explain what is causing this error?, Is this error caused by a limitation of the tkinter package or of the system's hardware (e.g. RAM, GPU, ... etc)? Anyway to overcome this?

I found a similar question but it was posted 9 years ago. I do not know if it is still relevant. Appreciate your assistance.

Update:

Following what was tried by the similar question, I added:

Option "VideoRam" "65536" Option "CacheLines" "1980" 

into the Section "Device" segment of /etc/X11/xorg.conf , i.e it is now:

Section "Device" Identifier "Device0" Driver "nvidia" VendorName "NVIDIA Corporation" Option "VideoRam" "65536" Option "CacheLines" "1980" EndSection 

The error changed to:

X Error of failed request: BadAlloc (insufficient resources for operation) Major opcode of failed request: 53 (X_CreatePixmap) Serial number of failed request: 128544 Current serial number in output stream: 128552 

The Current serial number in output stream: 140097 dropped to 128552.

The explanation of XCreatePixmap is given here. It states that BadAlloc occurs when the server failed to allocate the requested source or server memory.

I tried to create a test code to simulate the error. Although it failed to simulate the X BadAlloc error, it provides a simplified view of the scenario when the error occurred in my code. Nonetheless, I did learn that the max grid rows or columns allowed by tkinter is < 10000 because it will return _tkinter.TclError: row out of bounds. So if my original code is hitting the error when the quantity value used is 1800, is not related to _tkinter.TclError: row out of bounds. I wonder if my error is related to one of the thumbnails supplied to my original code.

Test code:

import tkinter as tk import tkinter.ttk as ttk from PIL import Image, ImageTk class App(ttk.Frame): def __init__(self, parent, file, quantity): super().__init__(parent) self.parent = parent self.quantity = quantity self.image = ImageTk.PhotoImage(Image.open(file)) self.checkbuttons = [] self.checkvalues = [] self.create_widgets() def create_widgets(self): for i in range(self.quantity): self.checkvalues.append(tk.BooleanVar()) self.checkbuttons.append( ttk.Checkbutton(self, image=self.image, variable= self.checkvalues[-1]) ) self.checkbuttons[-1].grid(row=i, column=0) if __name__ == "__main__": root = tk.Tk() app = App(root, 'thumbnail.jpg', 9000) app.grid(row=0, column=0) root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) root.mainloop() 

thumbnail

8
  • The question you posted has updates from within the past few years so it seems like it's still relevant. It seems like the X window system has an internal limit to the number of resource identifiers it can create, and you're hitting that limit. If all else fails, I'd think the best solution is to either render the thumbnails into big chunks instead of separate images, or only generate thumbnails that are meant to be currently visible. I'm no UI designer so those might not be great suggestions, keep in mind. Commented Feb 10, 2023 at 16:41
  • 1
    Please create a minimally reproducible example that demonstrates this problem. Commented Feb 10, 2023 at 17:33
  • See minimal reproducible example. And @Сергей Кох, you can use the magic link [mre]. Anyway I suspect a bug in your code because the memory was sufficient. Commented Feb 11, 2023 at 2:33
  • Are you using tkinter.update in your code? Also have a look at this answer don't know if it could be related to your environment. Commented Feb 11, 2023 at 7:16
  • @Thingamabobs My code did not use tkinter.update command. Also, I made sure the syntax .update is not used but it is always .update_somethingelse. Could be the issue. Same as what @Randomdavis suggested. Commented Feb 11, 2023 at 7:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.