Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4020736
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:15:55+00:00 2026-05-20T10:15:55+00:00

I realise the answer is very likely to be ‘no’! Basically, I have a

  • 0

I realise the answer is very likely to be ‘no’!

Basically, I have a graph (the nodes and edges kind) which represents a grid of squares; each node object contains references to every other node that this node has an edge to, which seems to mean that when the graph is serialised using cPickle.dump it traverses every node in the graph in a depth-first fashion, meaning that for a well-connected graph representing a 16×16 grid, it’s effectively treating it as a 256-level-deep data structure. This means that larger grids very quickly overrun the default maximum Python recursion depth, particularly since experimentation suggests it seems to take about 4 calls on the stack to go an extra level into the data structure.

The thing is, I also have a dict-of-dicts that refers into this graph in such a way as to allow me to use cartesian coordinates to find particular nodes (e.g. “node = nodes[3][6]”). So conceptually, it’s not a highly-nested data structure at all, it’s a fairly flat one which happens to have a lot of sideways references, but it seems that cPickle works entirely depth-first (which I understand is by far the easiest way to work).

Now, I know about sys.setrecursionlimit(), and I’ve done some experimentation to find out how big I’d need to set the limit for what size of graph, so that’s the ‘easiest’ option. I’m aware that I could just quit the node-to-node links and rely on the dict-of-dicts to maintain the grid and a separate flat structure to maintain edge weightings, but there are various reasons I’d like to avoid that – not least that the node-to-node links allow for a more intuitive use of the data structure. I believe from what I’ve read that I should be able to provide my own implementations of __getstate__ and __setstate__ and override the pickling functionality, but obviously that’s a non-trivial amount of work. If there were a way to get cPickle (or pickle, I’m not fussy!) to use a breadth-first traversal, it should solve the problem pretty simply!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:15:56+00:00Added an answer on May 20, 2026 at 10:15 am

    Writing a suitable __getstate__() method does not seem to be that complicated after all. Try something like

    class Node(object):
        def __getstate__(self):
            state = self.__dict__.copy()
            state.pop("neighbours")
            return state
    

    This will pickle all attributes of Node instance except for the neighbours attribute, which I assume to contain the links to the neighbours. (You don’t need a __setstate__() method.)

    After unpickling the whole graph, you will have to recreate the links to the neighbours on all nodes, but this shouldn’t be that difficult either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realise that this is a very basic question, but it is one which
Firstly, I realise that this is a very similar question to this one: Which
I realize this question is very likely to have been asked before, but I've
I realize that the answer to this question is likely quite obvious (if somewhat
I had an answer before and it was very helpful, thus I modified my
I have a very simple command line Java application that I wish to port
I am using Delphi 2009. I have a very simple data structure, with 2
Say I have a Dictionary object which contains many instances of an object called
I realize that this question is impossible to answer absolutely, but I'm only after
I realize there's no definitely right answer to this question, but when people talk

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.