Skip to content

Have imp.cache_from_source() raise NotImplementedError when cache tag not available #59261

Closed

Description

@brettcannon
BPO 15056
Nosy @brettcannon, @birkenfeld, @merwok, @ericsnowcurrently
Dependencies
  • bpo-15166: Implement imp.get_tag() using sys.implementation
  • Files
  • cachetag.patch: Possible patch
  • 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 = None
    closed_at = <Date 2012-07-09.17:59:21.100>
    created_at = <Date 2012-06-13.17:10:51.716>
    labels = ['easy', 'library', 'release-blocker']
    title = 'Have imp.cache_from_source() raise NotImplementedError when cache tag not available'
    updated_at = <Date 2012-07-09.17:59:21.099>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2012-07-09.17:59:21.099>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-07-09.17:59:21.100>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2012-06-13.17:10:51.716>
    creator = 'brett.cannon'
    dependencies = ['15166']
    files = ['26061']
    hgrepos = []
    issue_num = 15056
    keywords = ['patch', 'easy']
    message_count = 10.0
    messages = ['162712', '162713', '162801', '163289', '163727', '163730', '163799', '164100', '165100', '165101']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'georg.brandl', 'eric.araujo', 'Arfrever', 'python-dev', 'eric.snow', 'Pranav.Ravichandran']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'test needed'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue15056'
    versions = ['Python 3.3']

    Activity

    1. brettcannon commented on Jun 13, 2012

      @brettcannon
      MemberAuthor

      Both imp.cache_from_source() and source_from_cache() should throw NotImplementedError when sys.implementation.cache_tag is None. See the thread starting at http://mail.python.org/pipermail/python-dev/2012-June/120145.html for discussion of this decision.

    2. merwok commented on Jun 13, 2012

      @merwok
      Member

      It seems to me there is overlap between sys.implementation.cache_tag and sys.dont_write_bytecode. I was expecting sys.impl.cache_tag to be purely informational, and not actually controlling some behavior. “If cache_tag is set to None, it indicates that module caching should be disabled”: isn’t that the job of sys.dont_write_bytecode?

      (The difference that I see is that sys.impl.cache_tag is defined by the VM and dont_write_bytecode by each interpreter invocation; I was expecting VMs that never want to write bytecode to just always set dont_write_bytecode to False, i.e. make -B redundant.)

    3. brettcannon commented on Jun 14, 2012

      @brettcannon
      MemberAuthor

      So sys.dont_write_bytecode is there to prevent bytecode writing but not loading. This is an issue for some systems (e.g. clusters) where there are so many processes running Python that they start to trample each others bytecode files and it leads to malformed data. If you set sys.implementation.cache_tag to None you stop all bytecode usage (reading and writing), and thus is "disabled" entirely, not just for writing.

    4. PranavRavichandran commented on Jun 20, 2012

      PranavRavichandranmannequin
      Mannequin

      First-time contributor here, so just to make sure, let me just clarify this - the trunk builds fine, but one of the tests, test_urllib2_localnet, fails, I'm not sure why. Also, the patch is kind of messed up because of changes to Python/importlib.h. I looked this up on google, but wasn't able to find much help. Awaiting feedback :)

    5. merwok commented on Jun 24, 2012

      @merwok
      Member

      So sys.dont_write_bytecode is there to prevent bytecode writing but not loading.
      Ah right. Providing a way to avoid reading them sounds good.

      If you set sys.implementation.cache_tag to None you stop all bytecode usage (reading and writing)
      This I feel uncomfortable with. First, I would separate writing and reading; second, I think of sys.implementation as a read-only information holder, and would think it immutable (note that I haven’t read the latest version of the PEP); just like sys.flags.dont_write_bytecode does not change but sys.dont_write_bytecode can change. So even though I think sys has a lot of attributes, the cleanest thing here would be a new sys.dont_read_bytecode attribute (as was proposed in the thread), maybe also with a new command-line option (or using -BB) and environment variable.

    6. ericsnowcurrently commented on Jun 24, 2012

      @ericsnowcurrently
      Member

      Brett meant the implementation would set it. You'd still expect it to not change values during the execution of the interpreter. I suppose anyone could change that value, but I'd see that more as a consenting adults situation.

    7. brettcannon commented on Jun 24, 2012

      @brettcannon
      MemberAuthor

      Thanks for the patch, Pranav. I'm probably going to be too busy for a couple of weeks, so I won't look at this immediately, but I wanted to let you know I will eventually get to it.

    8. birkenfeld commented on Jun 26, 2012

      @birkenfeld
      Member

      Moving back to blocker for beta2.

    9. python-dev commented on Jul 9, 2012

      python-devmannequin
      Mannequin

      New changeset e86330669bb5 by Brett Cannon in branch 'default':
      Issue bpo-15056: imp.cache_from_source() and source_from_cache() raise
      http://hg.python.org/cpython/rev/e86330669bb5

    10. brettcannon commented on Jul 9, 2012

      @brettcannon
      MemberAuthor

      I released Pranav's patch and fleshed it out with docs, tests, and changes to importlib's use of cache_from_source().

    11. 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

    No one assigned

      Labels

      easyrelease-blockerstdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions