pulling multiple instances of a module into memory

Discussion in 'Python' started by Gabriel Jiva, Jun 27, 2005.

  1. Gabriel  Jiva

    Gabriel Jiva Guest

    I have a Python app, spam.py, that uses a C shared library, eggs.so.
    This shared library is an interface that makes connections to another
    system (Ham), and among other things uses callback functions.
    Therefore, if I want to make multiple connections to Ham, I need
    eggs.so to be instantiated in memory multiple times so that everything
    works fine.

    Right now, in spam.py, let's say I want to make two connections to the
    Ham system. I call

    eggs.start('Connection1')
    eggs.start('Connection2')

    On the second one, I get a 'duplicate call' error. Because Python is
    optimized to only load a module into memory once, I can never make more
    than one connection from the same Python script.

    Any ideas to work around this would be great.

    Gabriel
     
    Gabriel Jiva, Jun 27, 2005
    #1
    1. Advertising

  2. Gabriel  Jiva

    Grooooops Guest

    in spam.py, how about something like this:

    try:
    eggs.someFunction()
    except:
    import eggs
     
    Grooooops, Jun 27, 2005
    #2
    1. Advertising

  3. Gabriel  Jiva

    infidel Guest

    Do you have control over the eggs.so module? Seems to me the best
    answer is to make the start method return a connection object

    conn1 = eggs.start('Connection1')
    conn2 = eggs.start('Connection2')
     
    infidel, Jun 27, 2005
    #3
    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. hoeeg (at) post4.tele.dk

    Problem with multiple instances of a module

    hoeeg (at) post4.tele.dk, Apr 20, 2005, in forum: Perl
    Replies:
    1
    Views:
    2,559
    Alan D. Salewski
    Apr 22, 2005
  2. John Wohlbier
    Replies:
    2
    Views:
    367
    Josiah Carlson
    Feb 22, 2004
  3. Replies:
    8
    Views:
    465
    James Stroud
    Jan 29, 2009
  4. Ian Kelly
    Replies:
    0
    Views:
    425
    Ian Kelly
    Jul 5, 2010
  5. Chris Rebert
    Replies:
    1
    Views:
    658
    kedra marbun
    Jul 6, 2010
Loading...

Share This Page