(This message has been automatically imported from the retired mailing list)
Hello, I’m referring to an older discussion we had about hot-deploying a =
module which is imported by other hot-deployed code.
In my case the hot deployed module contains a base class for services (wh=
ich works OK)
and an error class which subclasses Exception (that’s where problems begi=
n).
class MyError(Exception):
pass
class BaseService(Service):
…
at the end of the file
mod =3D imp.new_module(‘base_service’)
for name in (‘BaseService’, ‘MyError’):
mod.dict[name] =3D locals()[name]
sys.modules[‘base_service’] =3D mod
Subclasses of BaseService which are deployed in their own module do this:=
from base_service import BaseService, MyError
class SpecificService(BaseService):
def handle(self):
try:
self.some_method_of_base_service() # raises MyError
except MyError:
no_problem()
except Exception:
panic()
it works fine 99 times out of 100, but sometimes MyError slips through th=
e first except block.
I always deploy the base_module as first file, then I wait for some secon=
d and then I deploy the other modules.
Any ideas?
On 04/29/15 16:38, Christopher Arndt wrote:
/Actually, there is a hackish way to do this: you can construct a module=
/>/dynamically in the Python file, which you hot-deploy. If tested this =
/>/once in Zato 1.1 and at least there it worked, but it’s hack. />//>/It=
goes like this: />//>/import imp />/import sys />//>/def testfunc(a, b):=
/>/return a ** b />//>/# Create the module object />/mod =3D imp.new_mod=
ule(‘mydynlib’) />//>/# populate module namespace />/for name in (‘testfu=
nc’, …): />/mod.dict[name] =3D locals()[name] />//>/# make it avail=
able globally for import />/sys.modules[‘mydynlib’] =3D mod />//>//>/Then=
in your service module you can do: />//>/from mydynlib import testfunc /=
//>//>/Chris/