-
Notifications
You must be signed in to change notification settings - Fork 80
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
File descriptor leak #180
Comments
|
Further researching, I have found that the current version of pygame being used (1.9.1release) has a bug in it that causes a segmentation fault when using a python file object to create the Font (http://archives.seul.org/pygame/users/Aug-2010/msg00020.html). This is fixed in later releases of pygame, however it seems that loading a single font file and creating multiple Font objects from it does not work anyways (at least not that I could get working), therefore it would still be necessary to open the font file for every new Font object, which is not ideal. It also seems like the font file cannot be closed after creating the Font object and is required for its lifespan. I am looking in to solutions, and have a few ideas to reduce the number of file descriptors. It looks like because the launcher is using the exec() family of functions, the current process is being overwritten with a new one, but all the previous fd's are inherited. It may be possible to migitate this and have those fd's close on exec. Looking into it. |
|
you are right, it's a leak :) |
|
fixed #183 |
|
Thanks @cuu ! closing. |
Every time you "reload" the launcher GUI (running and then exiting an application), it uses up more file descriptors (fd's). Once it uses up 1000+ fd's, the launcher can no longer open any new files and crashes when it tries to load a font from file (it loads all fonts every reload). It creates a LOT of fonts and is loading the file for the font for every size it needs (about 72 fonts/sizes, from sys.py/UI/fonts.py), but it never frees their fd's.
Instead the font files should be loaded into python once and reused for creating the fonts/sizes. Use the second constructor with object instead of filename: https://www.pygame.org/docs/ref/font.html#pygame.font.Font
Additionally, why are the fonts being recreated on reload at all anyways? At the very least, if the fonts need to be refreshed, the above should be used and combined with closing the files to free the descriptors, then reloaded, again only once, before re-creating the fonts/sizes.
You can use the following command to count the fd's being used by the launcher GUI at any given moment:
ps aux | grep [r]un.py | awk '{system("ls /proc/"$2"/fd")}' | wc -lRun the above command, then on the GameShell reload the launcher, then run the command after the launcher fully reloads. It will have an additional 72 fd's being used. Repeat and watch the fd count climb until it crashes when it reaches over 1000. It takes only 13 launcher reloads to crash (starts with 82 fd's, adding 72 each reload (72 + 13 = 936 + 82 = 1018).
The text was updated successfully, but these errors were encountered: