Alphonsus
Alphonsus

Reputation: 73

I am confused with the way execution is supposed to take place. I do not understand why the code is not executed. I am using shelve

This is a code segment that begins line 261 in my file.

if __name__ == '__main__':
  # main()
  print('Checkpoint 0')
  createShelve()
  print('Checkpoint 1')
  data = loadShelve()
  print('Checkpoint 2')
  for key in data.keys():
    print(key)

while debugging, I have added a bunch of print statements to createShelve and it looks exactly like this:

  def createShelve():
    global SHELVE_FILE
    filenames = getFilenames()
    data = {}
    print('Empty Data Now')
    for filename in filenames:
      build_data(filename, data=data)
      print('loaded file {}'.format(filename))
    print('Loading with {} keys'.format(len(data.keys())))


    recursionLimit = sys.getrecursionlimit()
    sys.setrecursionlimit(12657)  # used manual binary search to compute this
    print('Checkpoint A')
    try:
      print('Checkpoint B')
      with shelve.open(SHELVE_FILE) as result:
        result.update(data)
      print('File now contains data with {} keys'.format(len(data.keys())))
    except RecursionError:
      print('****Maximum recursion limit reached****')
      for ext in ('.bak', '.dat', '.dir'):
        print('Deleting {}'.format(filename + ext))
        os.unlink(filename + ext)
    print('Checkpoint C')
    sys.setrecursionlimit(recursionLimit)
    print('Checkpoint D')

Pointing directly at the problem here, I have 4 main print statements at checkpoints A, B, C, and D. Only A and B are printed and I still cannot think of any reason why the execution control will skip those lines. Also for the numeric checkpoints at the module level, only 'Checkpoint 0' is reached.

The only element of this code which I have not used before is the functions for setting recursion limit. I do not know if they could have some effect that is causing this. I have checked python's manual and I do not see something that might cause some effect. If you noticed from the checkpoints that were printed, it seems to suggest that only one of the setrecursionlimit calls were executed.

After I run the program, It executes and gives the following output but stops at that before closing without any errors. The data structure that I am attempting to save is a dictionary of keys which are the path to the html files and the corresponding tree of data that was processed from the html files. The question in this link is basically about the same problem. I will be looking to implement the solution there.

Shortened Output:

Checkpoint 0
Empty Data Now
loaded file .\json_data\SomeFile001.html
loaded file .\json_data\SomeFile002.html
loaded file .\json_data\SomeFile003.html
loaded file .\json_data\SomeFile004.html
loaded file .\json_data\SomeFile005.html
loaded file .\json_data\SomeFile006.html
loaded file .\json_data\SomeFile007.html
loaded file .\json_data\SomeFile008.html
loaded file .\json_data\SomeFile009.html
loaded file .\json_data\SomeFile010.html
loaded file .\json_data\SomeFile011.html

<snip>    

loaded file .\json_data\SomeFile040.html
loaded file .\json_data\SomeFile041.html
Loading with 41 keys
Checkpoint A
Checkpoint B

Upvotes: 0

Views: 24

Answers (0)

Related Questions