RE: How to load new class definitions at runtime?

Discussion in 'Python' started by Robert Brewer, Nov 11, 2004.

  1. > I'm looking for ways to load new class definitions at runtime (I'm not
    > talking about object instances here, so a persistent object database
    > isn't what I am looking for [1]). I'm aware of a few options, but I
    > would like to discuss the possible side effects for a potentially big,
    > long running application server.
    >
    > I am developing a business application based on workflow concepts. The
    > model is quite simple: a business process is modelled as a sequence of
    > tasks connected by actions. Actions can be re-used in different
    > contexts. The result is a very complex graph. Processes, tasks and
    > actions are implemented as classes. I opted to declare each action as
    > a different class, because each action has different Python code
    > attached to it. So simple object instances would not cut it. To allow
    > the system to be customized without taking the application server
    > offline, there must be a solution for these new class definitions to
    > be loaded at runtime.
    >
    > My current solution is simple. Class definitions have to be executed,
    > and for it to work, the class name and the source code (or the
    > compiled bytecode) is stored in a database. A class factory function
    > retrieves the correct class definition (based on the name), and simply
    > executes the code.


    If you have so many such classes that you _must_ put them in a database
    (and give up on existing version control systems like CVS), I don't have
    any recommendations. But if you have several which are fairly static and
    could survive in normal Python modules, feel free to steal my xray.py
    from http://www.aminus.org/rbre/python/xray.py and use it to dynamically
    load classes from Python modules as needed.


    Robert Brewer
    MIS
    Amor Ministries
    Robert Brewer, Nov 11, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,742
    Thomas Weidenfeller
    Oct 12, 2005
  2. Carlos Ribeiro
    Replies:
    7
    Views:
    367
    Michael Hudson
    Nov 26, 2004
  3. john
    Replies:
    8
    Views:
    369
    Nick Keighley
    Jun 22, 2010
  4. Stodge
    Replies:
    2
    Views:
    555
    Stefan Behnel
    Feb 17, 2012
  5. Rainer Weikusat
    Replies:
    1
    Views:
    213
    Rainer Weikusat
    Mar 8, 2013
Loading...

Share This Page