reload problem

Chris Emery deathfox at moochercrew.org
Sat Apr 27 01:00:01 EDT 2002


I am atempting to do something like the autoreloader, that will work for
some threaded objects I'm dealing with, which in 2.2.1 autoreloader
doesn't seem to like.  I figure if I update each instance of the class,
it will work properly.  Unfortunatly, I seem to be running into errors.
Any advice would be greatly welcomed, especially if I'm doing this the
wrong way, attached are the two files, and below is the output from my
session.

>>> import auto
>>> a = auto.auto(10)
>>> a.reload()
auto.pyc
0
stat <module 'stat' from '/usr/lib/python2.2/stat.pyc'>
__future__ <module '__future__' from '/usr/lib/python2.2/__future__.pyc'>
copy_reg <module 'copy_reg' from '/usr/lib/python2.2/copy_reg.pyc'>
posixpath <module 'posixpath' from '/usr/lib/python2.2/posixpath.pyc'>
auto <module 'auto' from 'auto.py'>
UserDict <module 'UserDict' from '/usr/lib/python2.2/UserDict.pyc'>
signal <module 'signal' (built-in)>
time <module 'time' from '/usr/lib/python2.2/lib-dynload/time.so'>
site <module 'site' from '/usr/lib/python2.2/site.pyc'>
__builtin__ <module '__builtin__' (built-in)>
sys <module 'sys' (built-in)>
atexit <module 'atexit' from '/usr/lib/python2.2/atexit.pyc'>
reloadtmp <module 'reloadtmp' from 'reloadtmp.py'>
posix <module 'posix' (built-in)>
types <module 'types' from '/usr/lib/python2.2/types.pyc'>
__main__ <module '__main__' (built-in)>
exceptions <module 'exceptions' (built-in)>
readline <module 'readline' from '/usr/lib/python2.2/lib-dynload/readline.so'>
os <module 'os' from '/usr/lib/python2.2/os.pyc'>
rlcompleter <module 'rlcompleter' from '/usr/lib/python2.2/rlcompleter.pyc'>
os.path <module 'posixpath' from '/usr/lib/python2.2/posixpath.pyc'>
<reloadtmp.reload object at 0x81541ec> auto

It appears that reload, is reloading it's own module, even if I pass in the fact that it's suposed to reload the auto module, any idea of why this is happening?

Chris
-------------- next part --------------
import time
import sys
import reloadtmp

class auto(object, reloadtmp.reload):
	"Thisis another doc string"
	def __init__(self, x):
		"""Yet another doc string"""
		self.x = x
		self.d = 0
		self.rinit()

	def count(self):
		"""This is a doc string"""
		self.d = 0
		for a in range(1, self.x + 1):
			self.d += a
			#time.sleep(1)
			print 'test'

	def reload(self):
		reloadtmp.reload.reload(self, "auto")
-------------- next part --------------
import os
import sys

class reload(object):
	def rinit(self):
		self.file = str(self.__module__ + ".pyc")
		lclass = str(self.__class__)
		lclass = lclass.split()
		lclass = lclass[1]
		lclass = lclass[1:-2]
		self.classname = lclass.split(".")

	def reload(self, modname):
		print self.file
		print os.stat(self.file[:-1])[8] >= os.stat(self.file)[8]
		mod = reload(sys.modules[modname])
		for a,b in sys.modules.items():
			print a, b
		print mod, self.__module__
		if os.stat(self.file[:-1])[8] >= os.stat(self.file)[8]:
			print mod
			for a in mod.__dict__:
				print a
			sys.stdout.flush()
			#for name, object in mod.__dict__[self.classname[1]].__dict__.items():
			#	self.__dict__[name] =  object
			#	print name, object
		


More information about the Python-list mailing list