Re: A thread import problem

Discussion in 'Python' started by Dieter Maurer, Jul 22, 2012.

  1. Bruce Sherwood <> writes:
    > ...
    > The failure of this test case suggests that one cannot do imports
    > inside secondary threads started in imported modules, something I keep
    > tripping over. But I hope you'll be able to tell me that I'm doing
    > something wrong!


    As you know multiple threads can be dangerous when they concurrently
    change common data structures. Locks are used to protect those
    data structures. Locking can introduce other problems - like deadlocks
    (something you seem to observe).

    I have not looked at the concrete implementation. However, the Python
    documentation suggests that the import machinery uses its own locks
    (beside the "Global Interpreter Lock"). It seems to be a "thread lock",
    which would mean that a thread is not blocked when it already
    holds the lock - however any other thread would block.
    This easily can lead to a deadlock -- when you wait for the other
    thread "in any way".

    There should be no problem when you complete the whole import chain
    without any waiting for the thread. However, should you start
    the GUI main loop inside the import chain, you will never complete
    this chain.
     
    Dieter Maurer, Jul 22, 2012
    #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. Stefan Seefeld
    Replies:
    3
    Views:
    963
  2. per9000
    Replies:
    7
    Views:
    413
    Magnus Lycka
    Feb 27, 2006
  3. Bruce Sherwood

    A thread import problem

    Bruce Sherwood, Jul 19, 2012, in forum: Python
    Replies:
    0
    Views:
    161
    Bruce Sherwood
    Jul 19, 2012
  4. Dennis Lee Bieber

    Re: A thread import problem

    Dennis Lee Bieber, Jul 19, 2012, in forum: Python
    Replies:
    0
    Views:
    176
    Dennis Lee Bieber
    Jul 19, 2012
  5. Dieter Maurer

    Re: A thread import problem

    Dieter Maurer, Jul 19, 2012, in forum: Python
    Replies:
    0
    Views:
    145
    Dieter Maurer
    Jul 19, 2012
Loading...

Share This Page