Re: [Python-Dev] bpo-33257: seeking advice & approval on the course of action

2018-05-14 Thread Ivan Pozdeev via Python-Dev

On 14.05.2018 22:05, Ivan Pozdeev wrote:

On 14.05.2018 21:58, Terry Reedy wrote:

On 5/14/2018 12:20 PM, Chris Barker via Python-Dev wrote:
On Wed, May 2, 2018 at 8:21 PM, Terry Reedy > wrote:


    On 5/2/2018 4:38 PM, Ivan Pozdeev via Python-Dev wrote:

    The bottom line is: Tkinter is currently broken


    This is way over-stated.  Many modules have bugs, somethings in
    features more central to their main purpose.

I'll suggest a re-statement:

tkinter is not thread safe,


Still over-stated.  If one uses tcl/tk compiled with thread support, 
tkinter *is* thread-safe.  This is 'as far as I know' from running 
posted 'failing' examples (possible with bug fixes) with 3.5+ on 
Windows, which is installed with tcl/tk 8.6, which defaults to 
thread-safe.


This means that you didn't (yet) read the letter that I attached to 
https://bugs.python.org/issue33479 .

Reciting the relevant section:

===
The reality is that with neither flavor of Tcl is Tkinter completely 
thread-safe, but with threaded flavor, it's more so:


* with nonthreaded Tcl, making concurrent Tcl calls leads to crashes 
due to incorrect management of the "Tcl lock" as per 
https://bugs.python.org/issue33257
* with threaded Tcl, the only issue that I found so far is that a few 
APIs must be called from the interpreter's thread 
(https://bugs.python.org/issue33412#msg316152; so far, I know 
`mainloop()` and `destroy()` to be this) -- while most can be called 
from anywhere. Whether the exceptions are justified is a matter of 
discussion (e.g. at first glance, `destroy()` can be fixed).
And another undocumented limitation for threaded Tcl: when calling 
anything from outside the interpreter thread, `mainloop()` must be 
running in the interpreter threads, or the call will either raise or 
hang (dunno any more details atm).

===


Tkinter was intended to also be thread-safe when using tcl/tk without 
thread support, which was the default for tcl/tk 8.5 and before. The 
posted examples can fail on 2.x on Windows, which comes with tcl/tk 
8.5 or before. _tkinter.c has some different #ifdefs for the two 
situations.



and yet it is documented as being thread safe


True in https://docs.python.org/3/library/tk.html
Unspecified in https://docs.python.org/3/library/tkinter.html


This is either a bug(s) in the implementation or the docs.


Both


So what are the solutions?

1) fix the docs -- unless tkInter is made thread safe really soon, 
and fixes are back-ported, this seems like a no brainer -- at least 
temporarily.


https://bugs.python.org/issue33479 'Document tkinter and threads'


2) fix the issues that make tkInter not thread safe


with non-thread tcl/tk.

https://bugs.python.org/issue33257 has a patch that might improve the 
situation for one type of call.  Fixing everything might not be 
possible.  AFAIK, there are currently no tests of thread safety.






--
Regards,
Ivan

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] bpo-33257: seeking advice & approval on the course of action

2018-05-14 Thread Ivan Pozdeev via Python-Dev

On 14.05.2018 21:58, Terry Reedy wrote:

On 5/14/2018 12:20 PM, Chris Barker via Python-Dev wrote:
On Wed, May 2, 2018 at 8:21 PM, Terry Reedy > wrote:


    On 5/2/2018 4:38 PM, Ivan Pozdeev via Python-Dev wrote:

    The bottom line is: Tkinter is currently broken


    This is way over-stated.  Many modules have bugs, somethings in
    features more central to their main purpose.

I'll suggest a re-statement:

tkinter is not thread safe,


Still over-stated.  If one uses tcl/tk compiled with thread support, 
tkinter *is* thread-safe.  This is 'as far as I know' from running 
posted 'failing' examples (possible with bug fixes) with 3.5+ on 
Windows, which is installed with tcl/tk 8.6, which defaults to 
thread-safe.


This means that you didn't (yet) read the letter that I attached to 
https://bugs.python.org/issue33479 .

Reciting the relevant section:

===
The reality is that with neither flavor of Tcl is Tkinter completely 
thread-safe, but with threaded flavor, it's more so:


* with nonthreaded Tcl, making concurrent Tcl calls leads to crashes due 
to incorrect management of the "Tcl lock" as per 
https://bugs.python.org/issue33257
* with threaded Tcl, the only issue that I found so far is that a few 
APIs must be called from the interpreter's thread 
(https://bugs.python.org/issue33412#msg316152; so far, I know 
`mainloop()` and `destroy()` to be this) -- while most can be called 
from anywhere. Whether the exceptions are justified is a matter of 
discussion (e.g. at first glance, `destroy()` can be fixed).

===
Tkinter was intended to also be thread-safe when using tcl/tk without 
thread support, which was the default for tcl/tk 8.5 and before. The 
posted examples can fail on 2.x on Windows, which comes with tcl/tk 
8.5 or before. _tkinter.c has some different #ifdefs for the two 
situations.



and yet it is documented as being thread safe


True in https://docs.python.org/3/library/tk.html
Unspecified in https://docs.python.org/3/library/tkinter.html


This is either a bug(s) in the implementation or the docs.


Both


So what are the solutions?

1) fix the docs -- unless tkInter is made thread safe really soon, 
and fixes are back-ported, this seems like a no brainer -- at least 
temporarily.


https://bugs.python.org/issue33479 'Document tkinter and threads'


2) fix the issues that make tkInter not thread safe


with non-thread tcl/tk.

https://bugs.python.org/issue33257 has a patch that might improve the 
situation for one type of call.  Fixing everything might not be 
possible.  AFAIK, there are currently no tests of thread safety.




--
Regards,
Ivan

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] bpo-33257: seeking advice & approval on the course of action

2018-05-14 Thread Terry Reedy

On 5/14/2018 12:20 PM, Chris Barker via Python-Dev wrote:
On Wed, May 2, 2018 at 8:21 PM, Terry Reedy > wrote:


On 5/2/2018 4:38 PM, Ivan Pozdeev via Python-Dev wrote:

The bottom line is: Tkinter is currently broken


This is way over-stated.  Many modules have bugs, somethings in
features more central to their main purpose.

I'll suggest a re-statement:

tkinter is not thread safe,


Still over-stated.  If one uses tcl/tk compiled with thread support, 
tkinter *is* thread-safe.  This is 'as far as I know' from running 
posted 'failing' examples (possible with bug fixes) with 3.5+ on 
Windows, which is installed with tcl/tk 8.6, which defaults to thread-safe.


Tkinter was intended to also be thread-safe when using tcl/tk without 
thread support, which was the default for tcl/tk 8.5 and before.  The 
posted examples can fail on 2.x on Windows, which comes with tcl/tk 8.5 
or before. _tkinter.c has some different #ifdefs for the two situations.



and yet it is documented as being thread safe


True in https://docs.python.org/3/library/tk.html
Unspecified in https://docs.python.org/3/library/tkinter.html


This is either a bug(s) in the implementation or the docs.


Both


So what are the solutions?

1) fix the docs -- unless tkInter is made thread safe really soon, and 
fixes are back-ported, this seems like a no brainer -- at least temporarily.


https://bugs.python.org/issue33479 'Document tkinter and threads'


2) fix the issues that make tkInter not thread safe


with non-thread tcl/tk.

https://bugs.python.org/issue33257 has a patch that might improve the 
situation for one type of call.  Fixing everything might not be 
possible.  AFAIK, there are currently no tests of thread safety.


--
Terry Jan Reedy


___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] bpo-33257: seeking advice & approval on the course of action

2018-05-14 Thread Chris Barker via Python-Dev
On Wed, May 2, 2018 at 8:21 PM, Terry Reedy  wrote:

> On 5/2/2018 4:38 PM, Ivan Pozdeev via Python-Dev wrote:
>
>> The bottom line is: Tkinter is currently broken
>>
>
> This is way over-stated.  Many modules have bugs, somethings in features
> more central to their main purpose.


I'll suggest a re-statement:

tkinter is not thread safe, and yet it is documented as being thread safe
(or at least not documented as NOT being thread safe)

This is either a bug(s) in the implementation or the docs.

So what are the solutions?

1) fix the docs -- unless tkInter is made thread safe really soon, and
fixes are back-ported, this seems like a no brainer -- at least temporarily.

2) fix the issues that make tkInter not thread safe -- apparently there is
a thread safe tcl/tk, so it should be possible, though I have to say I'm
really surprised that that's the case for an old C code base -- but great!

The problem here is that we'll need qualified people to submit and review
the code, and it really should get some extensive testing -- that's a lot
of work.

And it's going to take time, so see (1) above.

Another issue:

Many GUI toolkits are not thread safe (I have personal experience with
wxPython), so it's not so bad to simply say "don't do that" for tkInter --
that is, don't make tkInter calls from more than one thread.

However, wxPython (for example) makes this not-too-bad for multi-threaded
programs by providing thread-safe ways to put events on the event queue --
whether with wx.PostEvent, or the utilities wx.CallAfter() and
wx.CallLater(). This makes it pretty easy to keep the GUI in one thread
while taking advantage of threads for long running tasks, etc.

IIUC, tkinter does not have such an easy way to interact with the GUI from
another thread -- so maybe adding that would be a good first step.

I neither use tkinter, nor have the expertise to contribute this -- but
clearly Ivan does -- and maybe others would want to help.

-CHB


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] bpo-33257: seeking advice & approval on the course of action

2018-05-02 Thread Terry Reedy

On 5/2/2018 4:38 PM, Ivan Pozdeev via Python-Dev wrote:

The bottom line is: Tkinter is currently broken


This is way over-stated.  Many modules have bugs, somethings in features 
more central to their main purpose.



-- as in, it's not thread-safe (in both Py2 and Py3)


Meaning that tkinter calls in threads sometimes work, and sometimes not. 
Most people do not think of trying this, and are therefore not affected. 
 Others who want do either play it safe and desist or experiment to 
find out what does dependable work on their system.



despite being designed [as such].


Martin Loewis said this on a tracker issue several years ago, when he 
invited submission of patches he could review.  Too bad he is not active 
now that someone (you) finally submitted one.


The intention for Tkinter to be thread safe may have predated tcl/tk 
having a decent Mac version.


> and advertizing itself as such.

Where?  According to Firefox, the current 3.6 tkinter chapter does not 
contain the string 'thread'.


All the fix options require some redesign of either `_tkinter', or some 
of the core as well.


This should be discussed on the tracker.  Posting here was premature.

So, I'd like to get some kind of core team's feedback and/or approval 
before pursuing any of them.


Serhiy Storchaka is the tkinter maintainer.  He is aware of your patch,
https://github.com/python/cpython/pull/6444
having added himself as a reviewer.  Your comments since then on
https://bugs.python.org/issue33257
suggest that this is a first-draft patch that you yourself consider 
obsolete. In particular, your message today seems to, in effect, cancel 
the patch pending discussion of which fix option to pursue.  He might be 
waiting for you to push updates.


In any case, Serhiy is an extremely productive core developer, either 
submitting or merging nearly a patch a day.  I am sure he saw fixing 
other issues, including some other and older tkinter issues, before the 
releases this week, as higher priority.


--
Terry Jan Reedy

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] bpo-33257: seeking advice & approval on the course of action

2018-05-02 Thread Ivan Pozdeev via Python-Dev
The bottom line is: Tkinter is currently broken -- as in, it's not 
thread-safe (in both Py2 and Py3) despite being designed and advertizing 
itself as such.
All the fix options require some redesign of either `_tkinter', or some 
of the core as well.


So, I'd like to get some kind of core team's feedback and/or approval 
before pursuing any of them.


The options are outlined in https://bugs.python.org/issue33257#msg316087 .

If anyone of you is in Moscow, we can meet up and discuss this in a more 
time-efficient manner.


--
Regards,
Ivan

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com