You have some circular references.
d.u = u
u.append(d)
Pickle protocol 0 has issues with this, as you are experiencing. The simplest way to fix: specify protocol=-1
:
pickle.dump(u, open("ttt.pcl", 'wb'), protocol=-1)
From the docs:
There are currently 3 different protocols which can be used for pickling.
Protocol version 0 is the original ASCII protocol and is backwards compatible with earlier versions of Python. Protocol version 1 is the old binary format which is also compatible with earlier versions of Python. Protocol version 2 was introduced in Python 2.3. It provides much more efficient pickling of new-style classes.
Protocol 0 is the default (in python 2) and specifying -1 means "use the highest protocol available".