in lookdict, when ep->me_key != key && ep->me_hash != hash, i variable will change. However, this func will not stop. May I ask in what scenario does lookdict() become an infinite loop?
We will run multiple Python programs concurrently. They will all go to lookdict func defaultly, where the call stack is:merge_consts_recursive() ->PyDict_SetDefault() ->lookdict().
code link: cpython/Objects/dictobject.c at 648c44d3f7a020c7fed95d57b105738cf018a7cc · python/cpython · GitHub
You have not shared the code of lookdict so we cannot help you.
Please share the code and a simple test case to show the problem.
thanks, i update description
Why do you think lookdict will be an infinite loop? That should only happen if you mess with the internals of dictobject.
Every time I enter the body of the loop, I will set a global variable lookdict_cnt plus 1, finally lookdict_cnt have become over 200 million. I dump the backstrace of python program. The python program status is always running
Then please produce a small example setup that showcases this, without using the internals of python (e.g. without modifying dictobject.c
) and report it as a bug.
However, run python program will goto lookdict defaultly. We does not construct a small example. python program loading and running will goto this func defaultly. Multiple Python programs (e.g. printing hello world) encountered stuck when programs loading, executing, and exiting. I dumped backtrace and found that it entered lookdict.
Well, without an example, we can’t really help you. The answer to “when does lookdict become an infinite loop” is “when someone messed with the internals of dictobject, or there is a major bug somewhere that needs to be fixed”. By default, lookdict is never an infinite loop.
thanks, we will dump dict to observe
when lookdict enter an infinite loop, I dump all the dict,e.g. PyDictObject *mp. Found all ix, e.g. indices[i], Basically, are all greater than or equal to 0. Only two ix is -2. Nearly 3000+ ix are 0
And how did you get into that state? The dict object if used correctly should always have enough free spaces so that one of the hash functions should be able to find a free space easily. I.e. the question is how you constructed that dictionary object into such a broken state.
Every time I enter the body of the loop in lookdict, I will set a global variable lookdict_cnt plus 1. This lookdict_cnt ver 100000 times, I dump all the dict