Skip to content

[Internal] Fix the bug that Ctrl+C doesn't returns flow result.#3174

Merged
thy09 merged 4 commits intomainfrom
heta/fix-cancel
May 10, 2024
Merged

[Internal] Fix the bug that Ctrl+C doesn't returns flow result.#3174
thy09 merged 4 commits intomainfrom
heta/fix-cancel

Conversation

@thy09
Copy link
Copy Markdown
Contributor

@thy09 thy09 commented May 9, 2024

Description

Fix the bug that Ctrl+C doesn't returns flow result because the signal handler would raise an exception while asyncio.run cannot handle it correctly.

Note that for py<3.11, there is no default sigint handler when using asyncio.run to run an async function, so we add one for py<3.11 following python's implementation: https://github.com/python/cpython/blob/46c808172fd3148e3397234b23674bf70734fb55/Lib/asyncio/runners.py#L150
Such logic is initialized in this PR: python/cpython#32105

This pull request introduces significant changes to the src/promptflow-core/promptflow/_utils/async_utils.py file, aimed at improving the handling of asynchronous tasks and signal interruption. The changes also include minor modifications to several other files in the src/promptflow-core/promptflow/ directory.

Here are the key changes:

Signal Handling and Asynchronous Task Management:

  • src/promptflow-core/promptflow/_utils/async_utils.py: A new class _AsyncTaskSigIntHandler was added to handle SIGINT signals during the execution of asynchronous tasks. This class cancels the current task if a SIGINT signal is received, which is particularly useful for Python versions less than 3.11 where the default cancelling behavior is not supported. The function _invoke_async_with_sigint_handler was also added to invoke asynchronous functions with the SIGINT handler. The function async_run_allowing_running_loop was modified to use this new function. [1] [2] [3]

Minor Changes in Other Files:

All Promptflow Contribution checklist:

  • The pull request does not introduce [breaking changes].
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: suggested workflow.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@thy09 thy09 requested a review from a team as a code owner May 9, 2024 09:34
@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2024

promptflow SDK CLI Azure E2E Test Result heta/fix-cancel

  4 files    4 suites   4m 8s ⏱️
241 tests 205 ✅  36 💤 0 ❌
964 runs  820 ✅ 144 💤 0 ❌

Results for commit be2966e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2024

promptflow-core test result

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit be2966e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2024

SDK CLI Global Config Test Result heta/fix-cancel

6 tests   6 ✅  1m 15s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit be2966e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2024

Executor Unit Test Result heta/fix-cancel

792 tests   792 ✅  3m 43s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit be2966e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2024

Executor E2E Test Result heta/fix-cancel

243 tests   238 ✅  5m 31s ⏱️
  1 suites    5 💤
  1 files      0 ❌

Results for commit be2966e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2024

SDK CLI Test Result heta/fix-cancel

    4 files      4 suites   1h 1m 10s ⏱️
  690 tests   652 ✅  38 💤 0 ❌
2 760 runs  2 608 ✅ 152 💤 0 ❌

Results for commit be2966e.

♻️ This comment has been updated with latest results.

@thy09 thy09 merged commit b3257cc into main May 10, 2024
@thy09 thy09 deleted the heta/fix-cancel branch May 10, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants