FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ProcessPoolExecutor swallows falsy Exceptions · Issue #132063 · python/cpython · GitHub

Repository navigation

ProcessPoolExecutor swallows falsy Exceptions #132063

Closed

Description

Bug report

Bug description:

import sys
import concurrent.futures

class MyException(Exception):

    def __bool__(self):
        return False


def raiser():
    raise MyException("foo")

def main():
    with concurrent.futures.ProcessPoolExecutor() as p:
        print(p.submit(raiser).result())

if __name__ == "__main__":
    sys.exit(main())

This program prints None, but should fail and print a traceback

CPython versions tested on:

CPython main branch, 3.14, 3.13, 3.12, 3.11, 3.10, 3.9

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Apr 4, 2025
  2. YvesDup commented on Apr 4, 2025

    Contributor

    I think there is something wrong here in the __get_result(self) method of Future class:

    if self._exception:
    try:
    raise self._exception
    finally:
    # Break a reference cycle with the exception in self._exception
    self = None
    else:
    return self._result

    The test should be: if self._exception is not None: because if self._exception calls the __bool__ method of exception.

    Edit: same problem here on line 443

    # work_item can be None if another process terminated (see above)
    if work_item is not None:
    if result_item.exception:
    work_item.future.set_exception(result_item.exception)
    else:
    work_item.future.set_result(result_item.result)

  3. picnixz commented on Apr 4, 2025

    Member

    The test should be: if self._exception is not None: because if self._exception calls the bool method of exception.

    Well spotted. Indeed, this should be changed to is not None. More generally, are there other places in the stdlib (or in mp-related code) where we have this issue?

  4. YvesDup commented on Apr 4, 2025

    Contributor

    More generally, are there other places in the stdlib

    I saw these tests this morning:

    May I open a PR ?

  5. picnixz commented on Apr 4, 2025

    Member

    Unless they can make a silly bug, I think it's fine to keep them. However, unless @graingert wants to work on the issue itself, you may first fix the __get_result method first.

  6. YvesDup commented on Apr 4, 2025

    Contributor

    It's mandatory to work on both files /Lib/concurrent/futures/process.py and /Lib/concurrent/futures/_base.pyto fix this issue.

    This should fix the same issue with a ThreadPoolExcecutor.

  7. graingert commented on Apr 4, 2025

    ContributorAuthor
  8. added a commit that references this issue on Apr 8, 2025
  9. added a commit that references this issue on Apr 8, 2025
  10. added a commit that references this issue on Apr 8, 2025
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

    3.12only security fixes3.13only security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL