[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2021-05-13 Thread Ivan Naydonov


Ivan Naydonov  added the comment:

I recently faced this problem and this bug was very helpful to understand whats 
going on. Especially the comment about a problem being a tkinter reference 
leaked to a thread.

Most of the discussions in google results doesn't mention it (or at least it's 
not easy to find).

I understand that fixing this problem on tkinter side won't be easy (if even 
possible), but I think it would be very useful for everyone to extend error 
message to explain the problem and ideally add some information that can help 
identify problematic reference - at least the name of the thread it was deleted 
from.

--
nosy: +samogot

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2021-05-13 Thread Ivan Naydonov


Ivan Naydonov  added the comment:

I recently faced this problem and this bug was very helpful to understand whats 
going on. Especially the comment about a problem being a tkinter reference 
leaked to a thread.

Most of the discussions in google results doesn't mention it (or at least it's 
not easy to find).

I understand that fixing this problem on tkinter side won't be easy (if even 
possible), but I think it would be very useful for everyone to extend error 
message to explain the problem and ideally add some information that can help 
identify problematic reference - at least the name of the thread it was deleted 
from.

--
nosy: +samogot

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2021-05-13 Thread Ivan Naydonov


Ivan Naydonov  added the comment:

I recently faced this problem and this bug was very helpful to understand whats 
going on. Especially the comment about a problem being a tkinter reference 
leaked to a thread.

Most of the discussions in google results doesn't mention it (or at least it's 
not easy to find).

I understand that fixing this problem on tkinter side won't be easy (if even 
possible), but I think it would be very useful for everyone to extend error 
message to explain the problem and ideally add some information that can help 
identify problematic reference - at least the name of the thread it was deleted 
from.

--
nosy: +samogot

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2021-05-13 Thread Ivan Naydonov


Ivan Naydonov  added the comment:

I recently faced this problem and this bug was very helpful to understand whats 
going on. Especially the comment about a problem being a tkinter reference 
leaked to a thread.

Most of the discussions in google results doesn't mention it (or at least it's 
not easy to find).

I understand that fixing this problem on tkinter side won't be easy (if even 
possible), but I think it would be very useful for everyone to extend error 
message to explain the problem and ideally add some information that can help 
identify problematic reference - at least the name of the thread it was deleted 
from.

--
nosy: +samogot

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2021-02-16 Thread John Rouillard


John Rouillard  added the comment:

Sorry for the spam, but there is no silent post setup for this tracker.

On https://github.com/python/psf-infra-meta/issues/74 in July E-paine reports 
that he can't post to this issue. I just created an account linked to github to 
see if I am able to post.

--
nosy: +rouilj

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-20 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20707
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-20 Thread E. Paine


E. Paine  added the comment:

Trying to manually link the PR to this issue, I have opened 
https://github.com/python/cpython/pull/21532

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-19 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20697
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-19 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20695
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-19 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20696
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-19 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20694
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-19 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20693
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20677
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20676
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20675
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


E. Paine  added the comment:

It appears there are issues with this issue and so the PR for it is 
https://github.com/python/cpython/pull/21532

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20674
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20670
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20668
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-18 Thread E. Paine


Change by E. Paine :


--
keywords: +patch
pull_requests: +20669
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-15 Thread Richard Sheridan


Richard Sheridan  added the comment:

I stumbled into this in another project and I want to +1 the uncommenting 
solution. The problem occurs on __del__ rather than specifically in the gc 
somewhere (it happens when refs drop to zero too), so I wouldn't worry too much 
about killing the garbage collector.

It also looks like fixing the python part would be about 3 lines of 
non-user-facing code with weakrefs. Are you sure that's no-go?

Would it be any help to roll this fix into https://bugs.python.org/issue41176 
and https://github.com/python/cpython/pull/21299 since we fixed the quit() docs 
there?

--
nosy: +Richard Sheridan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-15 Thread Richard Sheridan


Richard Sheridan  added the comment:

I stumbled into this in another project and I want to +1 the uncommenting 
solution. The problem occurs on __del__ rather than specifically in the gc 
somewhere (it happens when refs drop to zero too), so I wouldn't worry too much 
about killing the garbage collector.

It also looks like fixing the python part would be about 3 lines of 
non-user-facing code with weakrefs. Are you sure that's no-go?

Would it be any help to roll this fix into https://bugs.python.org/issue41176 
and https://github.com/python/cpython/pull/21299 since we fixed the quit() docs 
there?

--
nosy: +Richard Sheridan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-15 Thread Richard Sheridan


Richard Sheridan  added the comment:

I stumbled into this in another project and I want to +1 the uncommenting 
solution. The problem occurs on __del__ rather than specifically in the gc 
somewhere (it happens when refs drop to zero too), so I wouldn't worry too much 
about killing the garbage collector.

It also looks like fixing the python part would be about 3 lines of 
non-user-facing code with weakrefs. Are you sure that's no-go?

Would it be any help to roll this fix into https://bugs.python.org/issue41176 
and https://github.com/python/cpython/pull/21299 since we fixed the quit() docs 
there?

--
nosy: +Richard Sheridan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-07-15 Thread Richard Sheridan


Richard Sheridan  added the comment:

I stumbled into this in another project and I want to +1 the uncommenting 
solution. The problem occurs on __del__ rather than specifically in the gc 
somewhere (it happens when refs drop to zero too), so I wouldn't worry too much 
about killing the garbage collector.

It also looks like fixing the python part would be about 3 lines of 
non-user-facing code with weakrefs. Are you sure that's no-go?

Would it be any help to roll this fix into https://bugs.python.org/issue41176 
and https://github.com/python/cpython/pull/21299 since we fixed the quit() docs 
there?

--
nosy: +Richard Sheridan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-06-18 Thread E. Paine


E. Paine  added the comment:

> ... would break any code that puts the interpreter in a non-main thread
Have people not been warned enough?! But seriously, looking anywhere on Google 
will scream at you to stop using using threads with tkinter, let alone having 
the interpreter in a thread.

I am not sure I agree with your statement that we would be keeping the 
interpreter exits, as that was only a 'fallback' if a delete was attempted in a 
thread. However, I agree with you that we should avoid breaking existing code 
where possible and so such a change shouldn't be added.

As for uncommenting CHECK_TCL_APPARTMENT in Tkapp_Dealloc, I looked at the 
blame and found that it was added as a comment:
https://github.com/python/cpython/commit/b5bfb9f38c786c3330b2d52d93b664588c42283dbecaus
I don't know the reason for adding it commented, but it is possible Martin 
couldn't find a situation in which it was required. My only problem with 
uncommenting it would be that I don't understand how the GC works. I suspect it 
would not be a problem, but if the error caused the GC to halt collecting, we 
would be in exactly the same situation (though I doubt this would be true).

> It should be done a bugfix regardless of anything else.
Agreed. Such a simple change to stop the interpreter crashing is definitely 
beneficial.

As for actually fixing the root of the problem, I suspect any of the changes 
you proposed, similar to mine, would be too controversial and not really go 
anywhere (being fairly large changes to fix just a handful of situations).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39093] tkinter objects garbage collected from non-tkinter thread cause crash

2020-06-17 Thread obserience


obserience  added the comment:

I looked into this in greater depth a while back and never followed up.

In "Modules/_tkinter.c"  the Tkapp_Dealloc() function has a commented out check 
that would ensure it isn't called from the wrong thread.

Tkapp_Dealloc(PyObject *self)
{
PyObject *tp = (PyObject *) Py_TYPE(self);
/*CHECK_TCL_APPARTMENT;*/
ENTER_TCL
Tcl_DeleteInterp(Tkapp_Interp(self));
LEAVE_TCL
PyObject_Del(self);
Py_DECREF(tp);
DisableEventHook();
}

If this is uncommented, garbage collection from a non-main thread will fail and 
the object will be leaked.
Adding a warning would be a good idea so the user knows that a memory leak has 
occurred.

**Doing this makes the code safe.** No more crashes. It should be done a bugfix 
regardless of anything else.


>> I propose that the Tkapp object can only be created in the main thread

Restricting interpreter object creation/destruction to the main thread is very 
much an API change that would break any code that puts the interpreter in a 
non-main thread.

Since we're keeping the objects around till the interpreter exits we still 
"leak" the memory and calling the destructor before the process exits has no 
benefits. Directly leaking the memory isn't any worse in terms of memory 
consumption and doesn't break currently working code.


My opinion is we should leak the memory, warn the user and forget about it. TCL 
interpreters are tiny and anyone who was doing this before was crashing their 
application anyway.

A nice to have would be changing the python tkinter code to cleanup the 
references when the associated GUI exits (as it arguably should)
--root.quit() doesn't do what the docs say and is regularly abused(ignore it)
--root.destroy() is more clear cut and a better candidate for adding cleanup 
behavior

implementations:
1)explicitly manage multiple references to the interpreter removing when 
appropriate (messy)
  --remove widget.tk refs on widget.destroy()
  --remove variable._tk when root.destroy() called (requires tracking variables 
with weakrefs)
2)replace root.tk with a weakproxy at initialisation and everything references 
the weakproxy (no other code changes)
3)replace widget.tk and variable._tk with a property that fetches root.tk
  --no weakrefs or explicit cleanup needed
  --**I favor this options**

For all implementations we need code to handle post-cleanup tk retrieval 
failure:
--Calls to root.quit() and other NOP equivalent methods should be ignored
--Variable sets should be ignored but trigger a warning
--Variable reads should RuntimeError since the TCL interpreter is dead

The user can shoot themselves in the foot by grabbing an explicit reference to 
the TCL interpreter but I've never seen that done and now it only causes a 
memory leak (which we can warn about).

Again, the python changes are nice to have but the "Modules/_tkinter.c" 
"CHECK_TCL_APPARTMENT;" macro needs to be uncommented.

I'd be happy to do the python side-changes if that's likely to be accepted.

--
title: tkinter objects garbage collected from non-tkinter thread cause panic 
and core dump -> tkinter objects garbage collected from non-tkinter thread 
cause crash

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com