Skip to content

Patch for new API method _PyImport_ImportModuleNoLock(char *name) #45908

Closed

Description

@tiran
BPO 1567
Nosy @gvanrossum, @kbkaiser, @tiran
Files
  • trunk_import_noblock.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 = 'https://github.com/tiran'
    closed_at = <Date 2008-01-04.13:14:41.224>
    created_at = <Date 2007-12-07.13:24:04.103>
    labels = ['interpreter-core', 'type-bug']
    title = 'Patch for new API method _PyImport_ImportModuleNoLock(char *name)'
    updated_at = <Date 2008-01-04.13:14:41.223>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2008-01-04.13:14:41.223>
    actor = 'christian.heimes'
    assignee = 'christian.heimes'
    closed = True
    closed_date = <Date 2008-01-04.13:14:41.224>
    closer = 'christian.heimes'
    components = ['Interpreter Core']
    creation = <Date 2007-12-07.13:24:04.103>
    creator = 'christian.heimes'
    dependencies = []
    files = ['9049']
    hgrepos = []
    issue_num = 1567
    keywords = []
    message_count = 6.0
    messages = ['58272', '58500', '59116', '59136', '59139', '59169']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'kbk', 'christian.heimes']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1567'
    versions = ['Python 2.6', 'Python 3.0']

    Activity

    1. tiran commented on Dec 7, 2007

      @tiran
      MemberAuthor

      The patch adds a new API method _PyImport_ImportModuleNoLock(const char
      *name). It works mostly like PyImport_ImportModule except it does not
      block. It tries to fetch the module from sys.modules first and falls
      back to PyImport_ImportModule UNLESS the import lock is held by another
      thread.

      It fixes several issues related to dead locks when a thread uses a
      function that imports a module but another thread holds the lock. It
      doesn't require static caching of modules.

      The patch is against py3k but I can backport it to 2.6.

    2. added
      interpreter-core
      on Dec 7, 2007
    3. self-assigned this
      on Dec 7, 2007
    4. added
      type-bug
      on Dec 7, 2007
    5. kbkaiser commented on Dec 12, 2007

      @kbkaiser
      Contributor

      Doesn't seem to be IDLE related, removed IDLE tag.

    6. gvanrossum commented on Jan 3, 2008

      @gvanrossum
      Member

      Can you produce a version of the patch that applies cleanly to 2.6? Then
      we can apply it there first and merge into 3.0 later.

      But I wonder. It seems this changes every single call to
      PyImport_ImportModule() in the core to _PyImport_ImportModuleNoLock().
      What's the point of the lock at that point?

    7. tiran commented on Jan 3, 2008

      @tiran
      MemberAuthor

      The patch does't replace all PyImport_ImportModule() calls with the new
      function. It replaces only the calls which may occure more than once and
      have a fixed name like "time".

      I've renamed the function to PyImport_ImportModuleNoBlock(). It should
      explain the purpose of the function better. It imports a module without
      blocking.

    8. gvanrossum commented on Jan 3, 2008

      @gvanrossum
      Member

      I see. I think there's still something uncomfortable with this function
      though -- it looks in sys.modules, but if it doesn't find it there, it
      invokes the full-blown import machinery, which calls the (possibly
      overridden) __import__ builtin, which in turn might do a relative import
      (at least in 2.6) or any amount of funny business.

      The only thing that really worries me here is the possibility of
      relative import. I'm thinking that relative import is really never
      meant to be when called from C, so perhaps it would be sufficient to
      modify the call to __import__ at the end of PyImport_Import() to add a
      5th parameter, zero, to always force absolute import. A quick concept
      test shows that this doesn't break anything, though it is worth checking
      the docs.

    9. tiran commented on Jan 3, 2008

      @tiran
      MemberAuthor

      Guido van Rossum wrote:

      The only thing that really worries me here is the possibility of
      relative import. I'm thinking that relative import is really never
      meant to be when called from C, so perhaps it would be sufficient to
      modify the call to __import__ at the end of PyImport_Import() to add a
      5th parameter, zero, to always force absolute import. A quick concept
      test shows that this doesn't break anything, though it is worth checking
      the docs.

      Committed in r59678
      I've changed PyImport_Import to always use absolute imports as
      requested. The docs didn't promise relative imports. It's probably a
      mistake to allow relative imports in the first place.

      I've also updated the docs and NEWS.

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

    interpreter-coretype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions