Re: Threaded import hang in cPickle.dumps

2009-11-11 Thread Christian Heimes
Zac Burns wrote:
> Using python 2.6
> 
> cPickle.dumps has an import which is causing my application to hang.
> (figured out by overriding builtin.__import__ with a print and seeing
> that this is the last line of code being run. I'm running
> cPickle.dumps in a thread, which leads me to believe that the first
> restriction here is the cause:
> http://docs.python.org/library/threading.html#importing-in-threaded-code
> 
> What can I do about this?

You can do two things to stop the import lock from dead locking.

* Never ever start a thread as a side effect of an import. This means
you must not start a thread in the body of a module. As I explained in
numerous other messages a well designed application imports all its
modules first. After all modules have been imported the components are
initialized and the threads are started.

* Import all modules that are referred inside your pickled data before
you unpickle.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded import hang in cPickle.dumps

2009-11-11 Thread Antoine Pitrou
Le Tue, 10 Nov 2009 10:50:33 -0800, Zac Burns a écrit :
> 
> cPickle.dumps has an import which is causing my application to hang.
> (figured out by overriding builtin.__import__ with a print and seeing
> that this is the last line of code being run. I'm running cPickle.dumps
> in a thread, which leads me to believe that the first restriction here
> is the cause:
> http://docs.python.org/library/threading.html#importing-in-threaded-code
> 
> What can I do about this?

Please report a bug at http://bugs.python.org
Better even if you can provide a small snippet of code which reproduces 
the problem reliably.

Regards

Antoine.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded import hang in cPickle.dumps

2009-11-11 Thread Zac Burns
On Tue, Nov 10, 2009 at 2:27 PM, Benjamin Peterson  wrote:
> Zac Burns  gmail.com> writes:
>> What can I do about this?
>
> Not run it in a thread.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Isn't requesting that pickle not be used in a thread a bit of a tall
order? Just thinking through the common use cases - database access,
server request threads, file IO... pickle is commonly used in threads.

Furthermore, the pickle documentation makes no mention of not being threadsafe.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded import hang in cPickle.dumps

2009-11-10 Thread Benjamin Peterson
Zac Burns  gmail.com> writes:
> What can I do about this?

Not run it in a thread.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded import hang in cPickle.dumps

2009-11-10 Thread Zac Burns
Oh, I'm pickling an NotImplementedError and it's importing exceptions.
--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games



On Tue, Nov 10, 2009 at 10:50 AM, Zac Burns  wrote:
> Using python 2.6
>
> cPickle.dumps has an import which is causing my application to hang.
> (figured out by overriding builtin.__import__ with a print and seeing
> that this is the last line of code being run. I'm running
> cPickle.dumps in a thread, which leads me to believe that the first
> restriction here is the cause:
> http://docs.python.org/library/threading.html#importing-in-threaded-code
>
> What can I do about this?
>
> --
> Zachary Burns
> (407)590-4814
> Aim - Zac256FL
> Production Engineer (Digital Overlord)
> Zindagi Games
>
-- 
http://mail.python.org/mailman/listinfo/python-list