-1

I have a (beginner) question.

I intend to run more than one webapp (pyramid web apps) and I have a common library (let's call that base app) that may be used by both webapps and includes pyramid configuration includes etc. These webapps will eventually be separate wsgi scripts (probably) ending up sitting in the same virtualenv.

My question is: What is the isolation level in python if I monkey patch classes in this library (I am currently dynamically changing bases for some of the classes in that library that may be referenced from both webapps).

for example:

in base app:

class_from_baseapp(grandparent):
    pass

in derived app 2:

from baseapp import class_from_baseapp
#do some stuff with this class
#and have another bunch of child classes too!
class_from_childapp2(class_from_baseapp):
    pass

in derived app 1:

from baseapp import class_from_baseapp
# then what I do is I change this dynamically to
# class_from_baseapp(grandparent, mixin_class): 
# by altering the class' __bases__


class_from_childapp1(class_from_baseapp):
    pass

So again, my question is: Will this monkey patching leak to the other web app (web app 1), if it imports/uses the same class as above? I don't know how process and thread isolation in python interpreters work.

4

1 回答 1

1

如果您正在运行单独的进程,则进程之间的隔离是完全的。每个 Python 解释器都有自己对类的引用。Monkey-patching in-memory modules 不会影响任何进程,但会影响修补完成的进程。

在同一个 Python 进程中运行的线程都使用相同的类。根据修补的完成方式(以及在修补发生之前线程获得的引用),补丁可能不会被所有线程看到,但通常会。

于 2013-04-15T14:58:10.867 回答