Multiple modules in a package importing one common module

I am writing a python package. I use the concept of plugins - where each plugin is a specialization of the Worker class. Each plugin is written as a module (script?) And generated in a separate process.

Due to the basic commonality between the plugins (for example, everyone extends the base class "Work"), the plugin module usually looks like this:

import commonfuncs

def do_work(data):
    # do customised work for the plugin
    print 'child1 does work with %s' % data

In C / C ++, we include security devices that prevent the inclusion of a header more than once.

I need something like this in Python, and if so, how can I make sure that commonfuncs is not "enabled" more than once?

+5
source share
1 answer

: import . "" (sys.modules, ), . .

+13

All Articles