Skip to content
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

Exception when a Shader object is deleted #17

Open
obiwac opened this issue May 8, 2021 · 13 comments
Open

Exception when a Shader object is deleted #17

obiwac opened this issue May 8, 2021 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@obiwac
Copy link
Owner

obiwac commented May 8, 2021

When the Shader class' __del__ function is called, an exception occurs:

ImportError: sys.meta_path is None, Python is likely shutting down

Haven't had the time to investigate this more, but it's likely not too big a problem as this only happens when __del__ is called on a Shader object, so only when exiting the program.

@obiwac obiwac added the bug Something isn't working label May 8, 2021
@obiwac obiwac self-assigned this May 8, 2021
@abhra2020-smart
Copy link
Contributor

abhra2020-smart commented May 10, 2021 via email

@abhra2020-smart
Copy link
Contributor

abhra2020-smart commented May 10, 2021 via email

@obiwac
Copy link
Owner Author

obiwac commented May 13, 2021

I think __del__ is getting called after the deletion of everything.

It's the destructor method for objects in Python, and one of the conditions for it to be called is indeed the program ending.

And, that error is an error with the interpreter itself, so you can report it on the Python forums.

Sorry, I don't understand what you're referring to

@abhra2020-smart
Copy link
Contributor

abhra2020-smart commented May 16, 2021 via email

@abhra2020-smart
Copy link
Contributor

abhra2020-smart commented May 16, 2021 via email

@abhra2020-smart
Copy link
Contributor

abhra2020-smart commented May 16, 2021 via email

@Jukitsu
Copy link
Contributor

Jukitsu commented Jul 11, 2021

Same, what’s going on? Maybe you can add some debugging code, if you know what I mean?

On Thu, May 13, 2021 at 10:22 AM Obiwac @.***> wrote: I think del is getting called after the deletion of everything. It's the destructor method for objects in Python, and one of the conditions for it to be called is indeed the program ending. And, that error is an error with the interpreter itself, so you can report it on the Python forums. Sorry, I don't understand what you're referring to — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#17 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLDW4G7XW64FZUYHEWN43TTNOK3TANCNFSM44MN47DQ .

Python use some kind of garbage collector from what I know, and once a program ends it frees all memory allocated by destructing every object in existing variables. However idk if its actually del that's called, since the del keyword sometimes only deletes the reference to that variable, not the variable itself :/

@obiwac
Copy link
Owner Author

obiwac commented Jul 12, 2021

del in Python does call the __del__ method of the object being deleted

@abhra2020-smart
Copy link
Contributor

the del method should set what it's deleting to none, then removing it from memory

@obiwac
Copy link
Owner Author

obiwac commented Jul 19, 2021

Sorry, could you elaborate on what you mean by that?

@Jukitsu
Copy link
Contributor

Jukitsu commented Sep 28, 2021

Alright i've been digging through and i've got a better idea how del works. Python uses reference counting to handle objects, and once an object no longer has any references it destroys them. But guess what ? del deletes a reference. So theorically a unique reference variable should be deleted using del. However the question is whether del is really a destructor or rather a wrapper for using the del keyword

@obiwac
Copy link
Owner Author

obiwac commented Jun 8, 2022

@phargobikcin
Copy link

phargobikcin commented Jun 8, 2022

There are no variables in python, just objects with references. Once there are no more references to an object, it will be deleted at some arbitrary future time (depending on the implementation, cpython is ref counted, and in cpython 2 at least it was quite deterministic (depends if there are circular references in your objects, which will still need broken by the so called garbage collector. pypy is usually compiled fully garbage collected, meaning it would happen whenever the gc runs.)
When a user defined object is about to be deleted and has the __del__ method defined, it will be called. but calling something in the guts of the interpreter already cleaning stuff up and then doing something complicated in your __del__ is clearly less than ideal, and hence frowned upon.
del keyword is for removing a reference from a dictionary, or module, or class, etc. nothing really to do with __del__.

Generally tl;dr it is best to avoid __del__ and find other ways to clean up. HTH ;)
Edit: dunder methods are bold in markdown...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants