This repository has been archived by the owner on Sep 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
SystemError: Handle is not initialized. in abc.py #1187
Labels
Comments
I manage to reproduce the error by trying the offending code 100.000 times. Below the script (Can someone else reproduce it by running the script?). Please note that I isolate the error to https://mail.python.org/pipermail/ironpython-users/2015-April/017442.html Looking forward some IronPython mantainer can debug inside the C# code to tackle the root of the problem! #
# file: testWeakSetError.py
#
#EXPLANATION ABOUT THE TEST SCRIPT:
# This test script is somehow based in the way abc.py class handle
# a weakSet as a cache for speeding up the ABCMeta.__instancecheck__(),
# which overrides the buildin isinstance(). The abc.py check the cache by
# testing "test=classX in WeakSetObjAsCache", which fails when
# the seldom exception is raised inside WeakSet.__contains__().
# The boolean test is a simple "test = item in WeakSetObject" which performs
# as expected 99.9% of the time and the result is True. "item" is a
# normal (not weak) reference, so it should not be killed
# by gc.collection, and "item" was added to WeakSetObject before. This
# boolean test is inside a loop that repeat the test 100.000 times. On every
# cycle of the loop, is it also added a new instance of
# a big (RAM) object (just 2kb to 12kb each obj), which will be
# stay as a weakref inside the WeakSet. Every 1000 cycles a gc.collection()
# is manually performed, which should clean some of this big objects. The
# error (exception) start to happen around cycle 12.000th (sometimes sooner).
# The error consist in an untrapped exception of the type:
# (ValueError) or (SystemError)
# After 100.000 cycles I count around 10 or 20 errors. For a real python
# application, that is enough frequent to stop the execution of a medium size
# optimization problem (Pulp library make intensive use of "isinstance()",
# and what buildin function use WeakSet under the hook as a cache.)
import gc, sys, traceback
from _weakrefset import WeakSet
#Big Object -> takes 2 to 12kb of RAM!
class BigObjClass(object):
def __init__(self,id):
self.useRAM = str(id)*1000 # Less than <100 or bigger than >10000, then no bug shows up (not knowing why?)
item = BigObjClass(id="AA")
weakSetObj = WeakSet()
weakSetObj.add(item) # adding an item instance
errorcount=0
for i in xrange(100000): #<- Do several loops until you get the error
#Simulating ram intensive python script (it must be inside the loop, otherwise no error shows up)
t = BigObjClass(id=i) # A new instance, takes 2 to 12kb of RAM!
weakSetObj.add(t) #<- Adding it to WeakSet. It is a weakref so the 2 to 12kb of RAM should be retrieved when gc.collect()
#The boolean Test
try:
test = item in weakSetObj #<- OFENDING CODE: THIS TEST IS WHERE SOMETIMES THE ERROR IS PRODUCED!!!
assert test==True
except (SystemError, ValueError) as e: # Exception as e:
errorcount += 1
(extype, exvalue, extraceback) = sys.exc_info()
print "\n####################################################"
print "Error in Loop",i,"coming from WeakSet.__contains__:"
print type(e), e
#print "------------- TRACEBACK -------------"
traceback.print_exception(extype,exvalue,extraceback,limit=10,file=sys.stdout)
print "####################################################\n"
# Garbage Collection from time to time (necessary to get the error)
if i%1000==0: # If too small (i.e. <100) the error is not shown! If too big -> memoryout exception
howmuch = gc.collect() #should collect the BigObjs created in the loop, but not "item" as it is normal referenced
print "loop",i, " doing gc.collect(): ",howmuch
print
print "In total:", errorcount, "errors in 100000 tests = %", errorcount/100000.0*100
print "End" |
For your information, this WeakSet.contains() error is impacting at least one other user of SolverStudio and PuLP. They see it in Iron Python 2.7.5 but not 2.7.4.1000 for some reason. Andrew |
I guess, this can now be closed as #1198 is merged. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I ran into a non-reproducible bug "SystemError: Handle is not initialized". It is very similar to the bug already posted here, it seems to have something to do with the garbage collector.
Stacktrace:
I was unable to deduce what causes this particular bug to appear and it seems to happen in a seemingly random fashion.
The text was updated successfully, but these errors were encountered: