« Auckland NZPUG presentation | Main | Notes on building C extensions with python »
Monday
Oct312011

You can not pickle an xml.etree Element

Yes that is right you will get an error that looks like this

PicklingError: Can't pickle <function copyelement at 0x226d140>: it's not found as
__main__.copyelement

Great how pickle doesn't tell you that it is an xml.etree.Element that is causing the problem or what this element is attached to.

I have been using the multiprocessing module that internally uses pickle to transfer inputs and outputs between processes and it will fail with an even more cryptic message if there is an Element object somewhere in the inputs or outputs.

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 310, in _handle_tasks
    put(task)
TypeError: expected string or Unicode object, NoneType found

To find this problem I replaced pool.map() with map() and pool.apply_async() with apply. Then I used pickle.dumps() on the inputs and outputs to find what was giving the problem.

pickle.dumps(thingee)
pickle.dumps(a)
pickle.dumps(b)
result = apply(my_func, (thingee, a, b))

Then once I had found the offending object I had to subclass pickle.Pickler to get the debugger to jump in at the right spot.

import pickle
class MyPickler (pickle.Pickler):
    def save(self, obj):
        try:
            pickle.Pickler.save(self, obj)
        except Exception, e:
            import pdb;pdb.set_trace()

Then call it like so

import StringIO
output = StringIO.StringIO()
MyPickler(output).dump(thingee)

And finally I got my answer

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (25)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    オメガ デビル コーアクシャル
  • Response
    Football is definitely one of the largest sports in America. It has a significant following.
  • Response
    Response: a forever recovery
    see here for greatest information on alcoholism treatment around
  • Response
    go here for the best Ferrari For Sale anywhere
  • Response
    Dynamic programming studies the situation where the optimization strategy will be based upon splitting the problem into more smaller subproblems. The equation that will identifies the relationship involving these kinds of subproblems.
  • Response
    Response: Xovilichter
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    Response: amazon.com
    The open-source code is typically a collaborative effort where programmers improve upon the source code and share the changes within the community so that other members can help improve it further.
  • Response
    Response: on front page
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    Response: camcorder reviews
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    Response: neighborhoods
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    年賀状シーズン前にチェックしよう hp インクカートリッジ 非純正インクカートリッジ カートリッジ インク hp インクカートリッジ が残っているのに突然インクが出なくなる 残量があるのにプリンターがカートリ カートリッジ ッジを認識しなくなり、 設置中に流れ出たインクが原因で混色してしまい、印刷結果に影響が出てしまう 時間が経過するとインクの色あせがひどい 非純正インクカートリッジには「増量」と銘打つものが多く、「インク量が多いお得」と考えがちだ。ところが、残量は十分なのに突然インクが出なくなる インクカ インクカートリッジ ー
  • Response
    榖戣採嫙侾 仏 丂姱朳挿姱偑婰幰夛尒偱乽偙傟偼傑偝偵悽奅嫲峇偲偄偆傋偒帠懺偱偁傝傑偡乿偲弎傋偨丅憼憡偼俧俈夛 キャノン インクカートリッジ 媍偱侾俁挍墌傪挻偊傞岞揑帒嬥榞偺妋曐乮搳擖乯傪栺偟偨丅幐嬈棪偑係丏俆亾傪忋夞偭偨丅擔宱暯嬒偑堦帪侾俁侽侽侽墌傪 エプソン インクカートリッジ 妱傝崬傫偩丅嬧峴偼昡壙帒嶻偺栚尭傝偐傜峏偵戄偟廰傝傪嫮傔偞傞傪摼側偄偲尵偆丅偄傢傟傞偲偙傠偺僨僼儗僗僷僀儔儖偵擖偭偰偄傞丅偙偺傛偆側宱嵪忬嫷偵偍偄偰戝敿偺恖偨偪偑枹宱尡偺偨傔偵柧妋側張曽獬傪傕偨側偄丅柉庡庡媊偺帪戙偱崙夛偼慺恖栚偵傕儌僞儌僞偟偰壥抐側曽嶔傪懪偪弌偣側偄丅擔杮 カートリッジ 敪
  • Response
    Response: ミュウミュウ
    prada エルメス 長財布 財布通話に関しては 発信元の電話番号は携帯の エルメス 長財布 着信履歴で知り、転送元は音声で知るわけです。勧められるまま プラダ ポーチ に・・・マンションで対応 プラダ ポーチ。 黒崎えり子さんのデザインの中で高い人気を誇るリボンを白いパネルに大胆に採用したデザイン エルメス財布メンズ。NFCの国際規格に準拠しているため、すべての携帯通信事業者やサービス提供会社にわたる相互運用が非接触サービスで実現します。 濃い味に執着する自分がいました プラダ トートバッグ。まあ、当た エルメス財布メンズ り前の話だ
  • Response
    Response: gucci 財布
    互換インクカートリッジpc関連情報 あすつく 対応 【ICチップ有】 エプソン インク イエロー PC prada 財布 パソコンからの写真のコピーに! リサイクルインク、詰替/詰替え/詰め替えインクよりも安心・安全な家庭用インクジ miumiu バッグ ェットプリンター用高品質汎用インクが安い! prada 財布 互換インクカートリッジの購入なら、激安 格安 通販 大安売りセール中のホビナビで! ※メール便は、「代金引換」のご利用はできません。 メール便で「代金引換」を選択された場合は、 miumiu バッグ 配送方法を「宅配 chanel バッグ 便
  • Response
    If we enhance our knowledge ability we should take help of education because education is only that enhances your abilities and you use your abilities to learning the best knowledge for yourself, for your families and also for the development, progress, prosperity and growth of your countries.
  • Response
    Response: 携帯買取
    マスクは必需品 今回は、あのロンブー淳のハートをガッチリつかん 白ロム買取 だ iphone 買取 香那さんに学ぶいい嫁のポイントを並べてみました番組内では、結婚会見を生放送でオンエアし、2人の過去の写真やお互いの実家に結婚報告に行った際のVTRなども放送されました。 約1800人(男女各900人ずつ)の足型を採取し、 それぞれの足の動きや足の状態を徹底分析。マッケイ製法で仕上げています。 暑い夏を快適 中古携帯 に過ごせる一着が見つかるはずです」と、スタッフさん。私が宿泊した部屋は、公園に面していたのですが、…』がすぱー
  • Response
    Stuart Mitchell Consulting - Journal - You can not pickle an xml.etree Element
  • Response
    I think the my pickler class is the main objective of the program. And later the main function which actually defines the best ways to import. I feel this would be the best program to around and learn form here.
  • Response
    Response: dissertation types
  • Response
  • Response
  • Response
    lab report writing service online

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>