Python dumps core with this.. how come?
Roey Katz
katz at glue.umd.edu
Fri Jan 21 21:28:55 EST 2000
I'm running Red Hat Linux 5.2, kernel 2.0.36 with 128 MB of memory.
"Python 1.5.2 (#2, Jun 13 1999, 17:00:15) [GCC 2.7.2.3] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam"
When I import this module, the interpreter segfaults.
Thiis module provides a little guard mechanism to keep track of
changes to registered variables. The error occurs when you ty to
instantiate class 'basic_monitor'. Also, I have another question (very
old, and I can't find this in the FAQ): I want to explicitly take a
reference to an integer. Take __setattr__() for example: is origval
a reference or merely a copy of self.res[ val ]? that is, do I change
self.res[ val ] by changing origval? Will Python2 implement some
sort of epxlicit referencing operator so that these situations won't
seem as confusing?
Whatever happened to
var := val
for assignment, and
var2 = &var1
for referencing? The addition of these explicit facilities would
greatly relieve a large portion of my Python problems (is there some
sort of rule-list to follow to figure out when exactly Python will
take a reference (like assigning from an object) or a literal value
(int's)? ).
Thanks :)
Roey
===================================================
"""module baseMonitor"
class resource_entry:
def __init__( self, minval, maxval, min_callback, max_callback ):
self.minval = minval
self.maxval = maxval
self.min_callback = min_callback
self.max_callback = max_callback
class basic_monitor:
def __init__( self ):
self.xres = [] # list of resource entries
def track( self, name, minval, maxval,
min_callback, max_callback ):
self.res[ name ] = resource_entry( minval, maxval,
min_callback, max_callback )
def __getattr__( self, name ):
return self.res[ name ]
def __setattr__( self, name, val ):
origval = self.res[ name ]
if minval < val < maxval:
origval = val
elif val < minval:
origval.min_callback()
elif val > maxval:
origval.max_callback()
if __name__=="__main__":
m = basic_monitor()
More information about the Python-list
mailing list