Skip to content

Short repeated regex patterns can skip signal handling #109631

Closed
@pan324

Description

@pan324

Bug report

Bug description:

I mentioned regex but this probably applies to other modules as well. In the code below, if the # line right after the findall is commented out (as it is right now), the code raises the exception past the try-except block on the print("Safely reached EOF.") statement. The exception happens one statement later than expected. NB: I tested all Python versions on Windows but only 3.11 on Linux.

import _thread, re from threading import Timer s = "ab"*20000000 pattern = re.compile("ab+") Timer(0.2, _thread.interrupt_main).start() try: pattern.findall(s) # print() ################################################################### except: print("Exception block") print("Safely reached EOF.")

CPython versions tested on:

3.9, 3.10, 3.11, 3.12, CPython main branch

Operating systems tested on:

Linux, Windows

Linked PRs

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-regextype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions