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: issue with list in Python 3.8.5
Type: behavior Stage: resolved
Components: Tkinter, Windows Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: andrei.avk, becky07, christian.heimes, paul.moore, shreyanavigyan, steve.dower, steven.daprano, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-05-08 13:04 by becky07, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Issue in Tkinter with Python 2.pdf becky07, 2021-05-09 23:55 example of screen and issue
Messages (23)
msg393256 - (view) Author: Mohamed (becky07) Date: 2021-05-08 13:04
I am using Python under Windows 10 on Dell for a log time.
All of my applications on Python were working fine.
Suddenly from the beginning of May, 
My apps do not update a "list" data after a new insert, 
even with small data volume.

As well as choosing old data from a list, 
a message appears stating that the identifier is out of range, 
and is working properly after restart.
Programs that do not use a list work fine.

After investigation, it appears memory issues.
How I solve the issue?
msg393257 - (view) Author: Mohamed (becky07) Date: 2021-05-08 13:06
I'm using tkinter 8.6 with Python
msg393260 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-08 14:46
Can you show an example code where this occurs? Which Python 3.8 subversion are you using? How do you conclude these are memory issues?
msg393266 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-05-08 16:01
I doubt it is a memory issue. Tell us what investigation you did that lead you to that conclusion.

Python code doesn't normally just stop working for no reason. I expect that you changed your code in some way and introduced a bug.

This is not a help desk for debugging your own code. If you need help with that, I recommend Reddit's r/learnpython, StackOverflow, or the Python-List mailing list.

If you still think that this is a bug in Python, not in your own code, please show us the smallest program you can that demonstrates the problem:

- what you did
- the result you expected
- the result that you actually got

For example, try this:

    L = [1, 2, 3]
    L.insert(0, 999)
    print(L)
    # you should get [999, 1, 2, 3]


If you get that result, your Python is working fine and the bug is in your code.
msg393287 - (view) Author: Mohamed (becky07) Date: 2021-05-08 22:23
I'm using tkinter for a long time, my application was running fine till 1st May, and suddenly happen this issue.

After adding a new data to a list, it showing in some places of tkinter components. For example, in treeview, it shows based on running specfic function, but on click it appear this message:

Traceback (most recent call last):
  File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "xxxxxxx.py", line 1423, in OnDoubleClick
    itemXid = assetinfo_lst[xrec][1]
IndexError: list index out of range

in OnDoubleClick:
    xrec = self.treedata.selection()[0]
    xrec = int(xrec[1:], 16) - 1

    itemXid = assetinfo_lst[xrec][1]

However, after exiting the program and restarting it, it is working properly.

it could be the mainloop is not working:
if __name__ == "__main__":
    root = Tk()
    App = MasterApp(root)
    root.mainloop()

Is an issue with a new update of Windows 10? MS suggest to reinstall tkinter and recover Windows
msg393311 - (view) Author: Mohamed (becky07) Date: 2021-05-09 09:24
I tried the following method:

    class MasterApp(object):
        def __init__(self, root):
        ....

        def fun_astinfo_add(self):
	    ...
	    assetinfo_lst.append(lst_values)
	    ...
	    MasterApp(root)

        ...
    if __name__ == "__main__":
        root = Tk()
        App = MasterApp(root)
        root.mainloop()

The program works properly, but the screen disappears and then reappears. Which means, that mainloop() works in the first time,
and when there is any change in the data, it does not work.

Reinstalling Tkinter is the right solution? Will it work?
msg393325 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-05-09 16:56
Hi Mohamed, you can try changing the following line:

    itemXid = assetinfo_lst[xrec][1]

to:

print('xrec',xrec)
itemXid = assetinfo_lst[xrec]
itemXid = itemXid[1]

This will show you if the index error is caused by xrec or by [1] lookup. If caused by xrec lookup, you will see what xrec value is at this point.
msg393340 - (view) Author: Mohamed (becky07) Date: 2021-05-09 22:04
I made changes but result is same:

    xrec = self.treedata.selection()[0]
    xrec = int(xrec[1:], 16) - 1

    print('xrec: ', xrec)
    itemXid = assetinfo_lst[xrec]
    itemXid = itemXid[1]



    Exception in Tkinter callback
    Traceback (most recent call last):
    File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
        return self.func(*args)
    File "xxxxxx.py", line 1463, in OnDoubleClick
    itemXid = assetinfo_lst[xrec]
    IndexError: list index out of range

    length of assetinfo_lst before a new insert: 16
    length of assetinfo_lst after a new insert: 17
    xrec:  xrec:  28


As I mentioned, It seems that the recent update of Windows has affected Tkinter, 
so that mainloop is not working after the first time
msg393341 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-05-09 22:24
Hi Mohamed,

From the output it looks like the app is trying to get item at index 28
from assetinfo_list, while that list is of only 17 length. So it seems
likely that either app is not inserting enough items into assetinfo_list,
or you are clicking on treedata.selection at a higher item than there are
assets for in the list, or something is going wrong with associating click
with the selection number.

To get further help, I think you will need to create a minimal runnable
example that shows the issue and upload it here.
msg393343 - (view) Author: Mohamed (becky07) Date: 2021-05-09 23:55
Please find attached, the demo with dummy data. As I mentioned, it was working fine until May 1st. 
Also, As I mentioned, in case I call MasterApp at the end of add function data appears correctly. This means a malfunction occurred after Windows Update, and it relates to mainloop

    class MasterApp(object):
        def __init__(self, root):
        ....

        def fun_astinfo_add(self):
	    ...
	    assetinfo_lst.append(lst_values)
	    ...
	    MasterApp(root)

        ...
    if __name__ == "__main__":
        root = Tk()
        App = MasterApp(root)
        root.mainloop()
msg393344 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-05-10 00:03
On Sun, May 09, 2021 at 10:04:29PM +0000, Mohamed wrote:

> As I mentioned, It seems that the recent update of Windows has affected Tkinter, 
> so that mainloop is not working after the first time

That isn't what it looks like to me. If updating Windows had affected 
Tkinter, IDLE would no longer work and there would be thousands of 
people affected. I see no sign that this is the case:

https://duckduckgo.com/?q=latest+update+of+windows+breaks+tkinter

It would be very, very suprising if you were the only person who has 
noticed that a Windows update broke Tkinter.

Mohamed, you said that you had done an investigation which showed memory 
corruption. What is your evidence for memory corruption?

So far there is no evidence for a bug in Tkinter or Python. This is not 
a help desk. There are many forums where you can get help debugging your 
program, you should create a minimal example and ask for help at

https://www.reddit.com/r/learnpython/

http://mail.python.org/mailman/listinfo/python-list

news:comp.lang.python

https://discuss.python.org/c/users/7

https://www.python.org/community/irc/

No matter which forum you go to, you will be asked for a minimal example 
demonstrating the problem:

http://www.sscce.org/

https://stackoverflow.com/help/minimal-reproducible-example

https://ericlippert.com/2014/03/05/how-to-debug-small-programs/

https://medium.com/swlh/how-to-ask-smart-questions-d02f053a02ac

http://www.catb.org/esr/faqs/smart-questions.html

Note that a minimal program **MUST** be runnable. There is no point just 
deleting lines of code and replacing them with "...", because the code 
won't run.
msg393345 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-05-10 00:14
On Sun, May 09, 2021 at 11:55:56PM +0000, Mohamed wrote:

> Please find attached, the demo with dummy data. As I mentioned, it was working fine until May 1st. 

If it was working fine until May 1st, I would start my investigation by 
looking at what changes where made to the source code on April 29, 30 
and May 1st.

Is your source code in a source control repository? Can you compare it 
to a backup?

> Also, As I mentioned, in case I call MasterApp at the end of add 
> function data appears correctly. This means a malfunction occurred 
> after Windows Update, and it relates to mainloop

Your traceback involves a keyerror and an index error. What makes you 
think this is a problem with the Tkinter mainloop rather than your own 
code?

You are trying to delete a module from sys.modules:

    del sys.modules['cm_asset_add']

(why?) but the key is not found. That exception is then caught and 
another exception raised.

It really looks to me that your callback function fun_asset_current is 
buggy. Why is it messing with sys.modules?

>     class MasterApp(object):
>         def __init__(self, root):
>         ....
> 
>         def fun_astinfo_add(self):
> 	    ...
> 	    assetinfo_lst.append(lst_values)
> 	    ...
> 	    MasterApp(root)

I'm not an expert at tkinter, but creating a new MasterApp object 
every single time you call the fun_astinfo_add method doesn't look 
right to me -- especially since you create that object, but then 
immediately discard it and it is instantly garbage collected.
msg393353 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-10 05:49
It doesn't seem to be a Python bug at all. This is pretty awkward that even without upgrading your Python your program is breaking. I don't know tkinter well but upgrading your Windows shouldn't affect tkinter at all. And as Steven described if that was the case IDLE wouldn't work and there would lot's of reports and issues like this.
msg393355 - (view) Author: Mohamed (becky07) Date: 2021-05-10 07:32
This statement in the main program which is calling a subprogram, to control for multiple runs. Even I close this statement, the issue is same.
    del sys.modules['cm_asset_add']	

I've contacted Microsoft support team, they have different opinions, about the impact of the latest Windows update which was on May 1st
msg393357 - (view) Author: Mohamed (becky07) Date: 2021-05-10 07:42
I chose Python to develop a huge information system.
I completed about 47%, and made a demonstration, so everything was working correctly, as evidenced by presence of the data
Now, I can't go back, and I can't move forward
msg393358 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-10 07:43
Are they saying this error is result of Windows update? (It may be. I didn't notice you're talking about 21H1, I thought you're talking about other patch updates.)
msg393359 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-05-10 07:47
For your information Python 3.8 is now in security fix-only mode and no longer receives regular updates. That means that any potential compatibility issues with Windows updates will not be addressed. Could you please update to Python 3.9 and try again?
msg393360 - (view) Author: Mohamed (becky07) Date: 2021-05-10 07:55
These are the latest updates:
    May 08, 2021, Microsoft Edge
    May 06, 2021, Microsoft OneDrive
    May 01, 2021, Update Health Tools

There is no an option to uninstall the following:
    May 01, 2021-KB4023057: Update for Windows 10 Update Service components 
    April 28, 2021—KB5001391 (OS Builds 19041.964 and 19042.964) Preview

I don't know, any of these updates might have an effect. 

I'm using a lot of modules, it means I have to install them again on Python 3.9
msg393361 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-10 07:58
Shortcut is store the output of pip in a file using,

pip freeze > file.txt

And then after installing Python 3.9

py -3.9 -m pip install -m file.txt
msg393362 - (view) Author: Mohamed (becky07) Date: 2021-05-10 07:59
Thanks a lot
msg393370 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-10 09:23
Today the nosy list is not working. When I don't even mean to add or remove someone, that person is automatically being added.
msg393371 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-10 09:23
Sorry, for the disturbance in the nosy list but it's glitching.
msg393408 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2021-05-10 15:25
Given that 3.8 is in security-fix-only mode and that it's not clear that this is actually a Python bug, I'm closing the issue.

If you can reproduce the issue in Python 3.9 with a short script, do please open a new issue (or reopen this one) with the reproducer and a description of what's going wrong.  In the meantime, please see either the python-list@python.org mailing list or the Users category of discuss.python.org for community support for using Tkinter.
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88242
2021-05-10 15:25:36zach.waresetstatus: open -> closed

type: enhancement -> behavior
components: + Tkinter

nosy: + steve.dower
messages: + msg393408
resolution: not a bug
stage: resolved
2021-05-10 15:15:19steve.dowersetnosy: - steve.dower
2021-05-10 09:23:48shreyanavigyansetmessages: + msg393371
2021-05-10 09:23:13shreyanavigyansetmessages: + msg393370
2021-05-10 09:22:08shreyanavigyansetnosy: - erlendaasland
2021-05-10 09:20:46shreyanavigyansetnosy: + erlendaasland
2021-05-10 07:59:37becky07setmessages: + msg393362
2021-05-10 07:58:39shreyanavigyansetnosy: + christian.heimes
2021-05-10 07:58:18shreyanavigyansetnosy: - christian.heimes
messages: + msg393361
2021-05-10 07:55:05becky07setmessages: + msg393360
2021-05-10 07:47:31christian.heimessetnosy: + christian.heimes
messages: + msg393359
2021-05-10 07:43:10shreyanavigyansetmessages: + msg393358
2021-05-10 07:42:34becky07setmessages: + msg393357
2021-05-10 07:32:39becky07setmessages: + msg393355
2021-05-10 05:49:26shreyanavigyansetmessages: + msg393353
2021-05-10 00:14:35steven.dapranosetmessages: + msg393345
2021-05-10 00:03:57steven.dapranosetmessages: + msg393344
2021-05-09 23:55:56becky07setfiles: + Issue in Tkinter with Python 2.pdf

messages: + msg393343
2021-05-09 22:24:15andrei.avksetmessages: + msg393341
2021-05-09 22:04:29becky07setmessages: + msg393340
2021-05-09 16:56:43andrei.avksetnosy: + andrei.avk
messages: + msg393325
2021-05-09 09:24:18becky07setmessages: + msg393311
2021-05-08 22:23:45becky07setmessages: + msg393287
2021-05-08 16:01:09steven.dapranosetnosy: + steven.daprano
messages: + msg393266
2021-05-08 14:46:19shreyanavigyansetnosy: + shreyanavigyan
messages: + msg393260
2021-05-08 13:06:35becky07setmessages: + msg393257
2021-05-08 13:04:44becky07create