Skip to content

Open shelves fail when Python exits #51181

Closed

Description

@lehmannro
mannequin
BPO 6932
Nosy @birkenfeld
Files
  • example.py: minimal example reproducing the error
  • shelve-warning.patch: patch to Doc/library/shelve.rst, trunk
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2009-09-17.16:16:19.732>
    created_at = <Date 2009-09-17.15:55:56.272>
    labels = ['extension-modules', 'type-bug', 'library', 'docs']
    title = 'Open shelves fail when Python exits'
    updated_at = <Date 2009-09-17.16:16:19.731>
    user = 'https://bugs.python.org/lehmannro'

    bugs.python.org fields:

    activity = <Date 2009-09-17.16:16:19.731>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2009-09-17.16:16:19.732>
    closer = 'georg.brandl'
    components = ['Documentation', 'Extension Modules', 'Library (Lib)']
    creation = <Date 2009-09-17.15:55:56.272>
    creator = 'lehmannro'
    dependencies = []
    files = ['14912', '14913']
    hgrepos = []
    issue_num = 6932
    keywords = ['patch']
    message_count = 2.0
    messages = ['92773', '92776']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'lehmannro']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6932'
    versions = ['Python 3.1', 'Python 2.7']

    Activity

    1. lehmannro commented on Sep 17, 2009

      lehmannromannequin
      MannequinAuthor

      I'm reopening bpo-5483 by Zhigang Wang (zhigang) as a separate bug.

      Shelves that are still open when Python terminates will try to sync. If
      writeback=True, this pickles cached items.

      In this example, serialization of Test() re-imports __main__, which is
      already gc'd, and raises:
      Exception cPickle.PicklingError: Can't pickle <class '__main__.Test'>:
      it's not the same object as __main__.Test" in <bound method
      Shelf.__del__ of {'a': <main.Test object at 0x...>}>

      The error is ignored (due to Python already tearing down) but all cached
      modifications are lost.
      The promise "[t]he __del__() method of the Shelf class calls the close()
      method, so the programmer generally need not do this explicitly" is not
      true with writeback enabled.

      I'm unsure if this error can be fixed (probably with atexit/weakref, but
      that's more trouble than gain). I attached a patch to the docs simply
      warning the user of this issue (+ documenting Shelf.close, + removing
      above quote).

    2. added
      docsDocumentation in the Doc dir
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Sep 17, 2009
    3. birkenfeld commented on Sep 17, 2009

      @birkenfeld
      Member

      Fixed docs (a bit differently) in r74876.

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    docsDocumentation in the Doc dirextension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions