python-minecraft-clone icon indicating copy to clipboard operation
python-minecraft-clone copied to clipboard

Exception when a Shader object is deleted

Open obiwac opened this issue 4 years ago • 13 comments

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 avatar May 08 '21 08:05 obiwac

I think del is getting called after the deletion of everything. I've seen this kind of error being reported on pybind11 for Python 3.9.0.

On Sat, May 8, 2021 at 9:02 AM Obiwac @.***> wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/obiwac/python-minecraft-clone/issues/17, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLDW4DHDYUQCRUVKLRPNTLTMTVZXANCNFSM44MN47DQ .

abhra2020-smart avatar May 10 '21 19:05 abhra2020-smart

BTW: the 'I think del is getting called after the deletion of everything.' bit is incorrect, or there would be a SyntaxError. And, that error is an error with the interpreter itself, so you can report it on the Python forums.

On Mon, May 10, 2021 at 8:38 PM Abhradeep De @.***> wrote:

I think del is getting called after the deletion of everything. I've seen this error being reported on pybind11 for Python 3.9.0. It may cause issues with your computer.

On Sat, May 8, 2021 at 9:02 AM Obiwac @.***> wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/obiwac/python-minecraft-clone/issues/17, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLDW4DHDYUQCRUVKLRPNTLTMTVZXANCNFSM44MN47DQ .

abhra2020-smart avatar May 10 '21 19:05 abhra2020-smart

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

obiwac avatar May 13 '21 09:05 obiwac

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 https://github.com/obiwac/python-minecraft-clone/issues/17#issuecomment-840434463, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLDW4G7XW64FZUYHEWN43TTNOK3TANCNFSM44MN47DQ .

abhra2020-smart avatar May 16 '21 09:05 abhra2020-smart

What, post it out on their Twitter page or something, I can not do that as I’m just an 8 year old lol

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 https://github.com/obiwac/python-minecraft-clone/issues/17#issuecomment-840434463, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLDW4G7XW64FZUYHEWN43TTNOK3TANCNFSM44MN47DQ .

abhra2020-smart avatar May 16 '21 09:05 abhra2020-smart

Wait, did I just expose my age?? Uh-oh…

On Sun, May 16, 2021 at 10:40 AM Abhradeep De @.***> wrote:

What, post it out on their Twitter page or something, I can not do that as I’m just an 8 year old lol

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 https://github.com/obiwac/python-minecraft-clone/issues/17#issuecomment-840434463, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLDW4G7XW64FZUYHEWN43TTNOK3TANCNFSM44MN47DQ .

abhra2020-smart avatar May 16 '21 09:05 abhra2020-smart

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 :/

Jukitsu avatar Jul 11 '21 17:07 Jukitsu

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

obiwac avatar Jul 12 '21 07:07 obiwac

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

abhra2020-smart avatar Jul 19 '21 15:07 abhra2020-smart

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

obiwac avatar Jul 19 '21 15:07 obiwac

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

Jukitsu avatar Sep 28 '21 15:09 Jukitsu

https://youtu.be/IFjuQmlwXgU

obiwac avatar Jun 08 '22 10:06 obiwac

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...

phargobikcin avatar Jun 08 '22 14:06 phargobikcin