New submission from Ivan Pozdeev <>:

(Marked only 2.7 as affected but this would affect any branch if built with 
nonthreaded Tcl.)

When running the attached repeatedly with 2.7.14 and 2.7 
head, win7 x64, two kinds of errors pop up randomly:

1. Crashes and freezes.
2. Exceptions on the console like:

Exception in thread Thread-14:
Traceback (most recent call last):
  File "C:\Users\Sasha\Documents\cpython\lib\", line 801, in __boots
  File "../tkt/", line 50, in run
    self.deliverToqueue((, z, y))
  File "../tkt/", line 133, in arrival_122
  File "C:\Users\Sasha\Documents\cpython\lib\lib-tk\", line 2328, in 
    return self._create('line', args, kw)
  File "C:\Users\Sasha\Documents\cpython\lib\lib-tk\", line 2310, in 
    *(args + self._options(cnf, kw))))
ValueError: invalid literal for int() with base 10: 'None'

Running the same code with the minimal required changes (attached as under 3.6 (same platform) goes without any errors.

Diagnostics showed:

1. Under debug Python, a crash became an MSVC double-free assertion error. The 
stacktrace is: 

2. The exceptions are caused by a `<canvas> create line` Tk call randomly 
returning "None" (a string) instead of an integer -- which it should never do 
according to its doc. Since it happens inconsistently, this also suggests a 
race condition.

3. In Tkapp_Call and SetVar, Tcl lock isn't held when creating/destroying Tcl 
objects for the call. The underlying fns modify the global state (free objects 
list, reference counters), so it should be held.
These two are the only such places in the code.

I've fixed this, will file the PR shortly. Holding the lock when calling 
Tkapp_CallDeallocArgs in Tkapp_Call eliminated the crashes and freezes, locking 
objects' creation in the same fn decreased the number of exceptions greatly, 
and locking creation in SetVar, too, eliminated them completely.

I did not check if objects created with AsObj in SetVar need to be disposed of 
like in Tkapp_Call.

Also have no idea how to autotest the fix. If someone does, I'm all ears.

components: Tkinter
messages: 315172
nosy: Ivan.Pozdeev
priority: normal
severity: normal
status: open
title: Race conditions in Tkinter with non-threaded Tcl
type: crash
versions: Python 2.7
Added file:

Python tracker <>
Python-bugs-list mailing list

Reply via email to