Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Threaded import hang in cPickle.dumps

12 views
Skip to first unread message

Zac Burns

unread,
Nov 10, 2009, 6:50:33 PM11/10/09
to pytho...@python.org
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

Zac Burns

unread,
Nov 10, 2009, 6:55:25 PM11/10/09
to pytho...@python.org
Oh, I'm pickling an NotImplementedError and it's importing exceptions.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games

Benjamin Peterson

unread,
Nov 10, 2009, 10:27:17 PM11/10/09
to pytho...@python.org
Zac Burns <zac256 <at> gmail.com> writes:
> What can I do about this?

Not run it in a thread.

Zac Burns

unread,
Nov 11, 2009, 8:40:38 PM11/11/09
to Benjamin Peterson, pytho...@python.org
> --
> 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.

Antoine Pitrou

unread,
Nov 11, 2009, 9:48:36 PM11/11/09
to pytho...@python.org
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.

Christian Heimes

unread,
Nov 11, 2009, 10:16:25 PM11/11/09
to pytho...@python.org
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

0 new messages