Author Ivan.Pozdeev
Recipients Ivan.Pozdeev
Date 2018-04-10.16:41:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
(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 create_line
    return self._create('line', args, kw)
  File "C:\Users\Sasha\Documents\cpython\lib\lib-tk\", line 2310, in _create
    *(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: Tkapp_Call->Tkapp_CallDeallocArgs->Tcl_DecrRefCount->TclFreeObj->free

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.
Date User Action Args
2018-04-10 16:41:10Ivan.Pozdeevsetrecipients: + Ivan.Pozdeev
2018-04-10 16:41:09Ivan.Pozdeevsetmessageid: <>
2018-04-10 16:41:09Ivan.Pozdeevlinkissue33257 messages
2018-04-10 16:41:09Ivan.Pozdeevcreate