Embedding Python in a threaded app

Discussion in 'Python' started by Jesper Nilsson, Nov 3, 2003.

  1. I've embedded python in a threaded app which contains two threads that may
    call into Python. The threads are created via the "C" api. If I can
    guarantee (1) that no python API is ever called at the same time from the
    two threads, is it necessary to init threads/aquire locks etc
    (PyEval_InitThreads, PyEval_AcquireThread and friends)?
    The reason (2) I ask this is that I'm afraid that the locking takes some
    time. Is this concern justified? The docs mention that there is a perfomance
    hit when threading is enabled.

    /Jesper

    (1)
    Every call into the python API is guarded with a lock. One reason I believe
    this to be more effective than python's internal locking is that nearly all
    calls are from the same thread (>99.9%).

    (2)
    Another reason is that the python source file "thread_nt.h" includes calls
    to GetCurrentThreadId(), which returns Win32's native thread ID.
    Jesper Nilsson, Nov 3, 2003
    #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. Harri Pesonen

    Re: Embedding Python in multi-threaded app

    Harri Pesonen, Sep 4, 2003, in forum: Python
    Replies:
    0
    Views:
    830
    Harri Pesonen
    Sep 4, 2003
  2. Mustafa Demirhan
    Replies:
    0
    Views:
    297
    Mustafa Demirhan
    Nov 9, 2004
  3. Mustafa Demirhan
    Replies:
    0
    Views:
    274
    Mustafa Demirhan
    Nov 9, 2004
  4. Mustafa Demirhan
    Replies:
    0
    Views:
    596
    Mustafa Demirhan
    Nov 9, 2004
  5. Craig Ringer
    Replies:
    1
    Views:
    399
    Mustafa Demirhan
    Nov 18, 2004
Loading...

Share This Page