This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Broken comparisons (probably caused by wrong caching of values)
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Thermi, steven.daprano
Priority: normal Keywords:

Created on 2018-01-07 14:15 by Thermi, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg309619 - (view) Author: (Thermi) Date: 2018-01-07 14:15
With Python 3.6.4 on Arch Linux, on three different hosts (one Skylake CPU, one i7-3820, one Xeon E5-2680, all running Arch Linux with the same Python version), the Python 3 interpreter behaves erratically in a script of mine.

The following symptoms occur:
1) Comparisons fail, although they logically need to succeed. The comparisons work a lot of the times, but sometimes, they don't.
2) Integers magically increase without ever being written to in the code after initially assigned in the constructor.

The behaviour changes if code is rearranged, variables and lines are added that do not pertain the broken comparisons, making accidental writes to memory or reads from unitialized memory likely.

The breakage occurs in the code between line 114 and the execution of the code in the recurse() method of the class Branch.

The script is here (https://gist.github.com/Thermi/05bc671436841670ac81b3b86217dd62). It basically only does some arithmetic with translation tables.
msg309620 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-01-07 15:16
That is nearly two hundred lines of quite complex code. What results are you expecting and what results are you getting?

I've just tried running it under Python 3.3 and 3.5 on a RedHat-based Linux, and after generating a large amount of output (271315 lines, including "IMPOSSIBLE CONDITION OCCURED!" 552 times) it raised KeyError.

I then tried again on an Ubuntu-based Linux, and got the same result.

Can you demonstrate the same problem with a smaller, simpler example? What reasons do you have for believing that this is caused by "wrong caching of values"? What values do you think are being cached, and where?

You say:

"Comparisons fail, although they logically need to succeed."

Which comparisons? Can you isolate those failing comparisons without all the extraneous code?

"Integers magically increase without ever being written to in the code after initially assigned in the constructor."

Which integers? What evidence do you have that they are changing?

Bottom line is, while it is conceivable that you've found an interpreter bug that exists in at least three versions of Python, going back many years, that nobody has noticed before, I think it is far more likely that the bug is in your code. I'm going to close this ticket for now, but if you have answers for my questions and good evidence of an interpreter bug (preferably with a short and simple demonstration, see http://sscce.org/) please feel free to re-open it.

Thank you.
msg309621 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-01-07 15:24
Oh, by the way... are you aware that the Recursor class defines a class attribute `branches` which is shared by all instances? You create multiple recursor objects, but they all share the same `branches` attribute. That might be intentional, but if not, that might explain the unexpected behaviour you are seeing.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76691
2018-01-07 15:24:03steven.dapranosetmessages: + msg309621
2018-01-07 15:16:55steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg309620

resolution: rejected
stage: resolved
2018-01-07 14:15:32Thermicreate