Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gevent): resolve asyncio-gevent compatibility issues #11900

Closed
wants to merge 6 commits into from

Conversation

mabdinur
Copy link
Contributor

Description

In some unix operating system tests (ex: ubuntuu), ddtrace module unloading breaks setting asyncio event loops. This issue can not be reproduced on macos.

Reproduction

import asyncio
import time

loop = asyncio.get_event_loop()
loop_id = id(loop)
new_loop = asyncio.new_event_loop()
new_loop_id = id(new_loop)

print(f"old: {loop_id} new: {new_loop_id}")
import pdb; pdb.set_trace()
asyncio.set_event_loop(new_loop)

check = asyncio.get_event_loop()
check_id = id(check)
print(f"check: {id(check)}")


while check_id != new_loop_id:
    print("MISMATCH")
    print(f"check: {id(check)}")
    time.sleep(1)
    check = asyncio.get_event_loop()
    check_id = id(check)

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

Copy link
Contributor

github-actions bot commented Jan 10, 2025

CODEOWNERS have been resolved as:

ddtrace/internal/coverage/_native.c                                     @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/_native.pyi                                   @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/instrumentation_py3_fallback.py               @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
.github/CODEOWNERS                                                      @DataDog/python-guild @DataDog/apm-core-python
ddtrace/contrib/pytest/plugin.py                                        @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/coverage.py                              @DataDog/ci-app-libraries
ddtrace/internal/coverage/code.py                                       @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/installer.py                                  @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/instrumentation.py                            @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/instrumentation_py3_10.py                     @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/instrumentation_py3_11.py                     @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/instrumentation_py3_12.py                     @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/instrumentation_py3_8.py                      @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/multiprocessing_coverage.py                   @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/report.py                                     @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/coverage/threading_coverage.py                         @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python
ddtrace/internal/module.py                                              @DataDog/debugger-python @DataDog/apm-core-python
pyproject.toml                                                          @DataDog/python-guild
riotfile.py                                                             @DataDog/apm-python
setup.py                                                                @DataDog/python-guild
tests/coverage/test_coverage_multiprocessing.py                         @DataDog/apm-core-python @DataDog/ci-app-libraries @Datadog/debugger-python
tests/coverage/test_coverage_threading.py                               @DataDog/apm-core-python @DataDog/ci-app-libraries @Datadog/debugger-python
tests/internal/test_module.py                                           @DataDog/debugger-python @DataDog/apm-core-python
ddtrace/internal/coverage/instrumentation_py3_9.py                      @DataDog/apm-core-python @datadog/ci-app-libraries @Datadog/debugger-python

@mabdinur mabdinur force-pushed the munir/2.11.0-with-reverts branch from 4f357ab to be9416a Compare January 10, 2025 18:13
replace = code.replace(
co_code=bytes(new_code),
co_consts=tuple(new_consts),
co_stacksize=code.co_stacksize + 4, # TODO: Compute the value!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
co_stacksize=code.co_stacksize + 4, # TODO: Compute the value!
co_stacksize=code.co_stacksize + 4, # TODO(<owner>): Compute the value!
comments must have ownership (...read more)

When using TODO or FIXME, specify who write the annotation. It's a best practice to remind you who created the annotation and have potential context and information about this issue.

View in Datadog  Leave us feedback  Documentation

replace = code.replace(
co_code=bytes(new_code),
co_consts=tuple(new_consts),
co_stacksize=code.co_stacksize + 4, # TODO: Compute the value!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
co_stacksize=code.co_stacksize + 4, # TODO: Compute the value!
co_stacksize=code.co_stacksize + 4, # TODO(<owner>): Compute the value!
comments must have ownership (...read more)

When using TODO or FIXME, specify who write the annotation. It's a best practice to remind you who created the annotation and have potential context and information about this issue.

View in Datadog  Leave us feedback  Documentation

lines.add(last_lineno)
except AttributeError:
# pseudo-instruction (e.g. label)
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Code Quality Violation

silent exception (...read more)

Using the pass statement in an exception block ignores the exception. Exceptions should never be ignored. Instead, the user must add code to notify an exception occurred and attempt to handle it or recover from it.

The exception to this rule is the use of StopIteration or StopAsyncIteration when implementing a custom iterator (as those errors are used to acknowledge the end of a successful iteration).

View in Datadog  Leave us feedback  Documentation

Comment on lines +30 to +31
if instr.name == "NOP":
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Code Quality Violation

too many nesting levels (...read more)

Avoid to nest too many loops together. Having too many loops make your code harder to understand.
Prefer to organize your code in functions and unit of code you can clearly understand.

Learn More

View in Datadog  Leave us feedback  Documentation

@pr-commenter
Copy link

pr-commenter bot commented Jan 10, 2025

Benchmarks

Benchmark execution time: 2025-01-10 19:54:36

Comparing candidate commit 822c0db in PR branch munir/2.11.0-with-reverts with baseline commit dc8591a in branch 2.11.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 154 metrics, 2 unstable metrics.

@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Jan 10, 2025

Datadog Report

Branch report: munir/2.11.0-with-reverts
Commit report: 822c0db
Test service: dd-trace-py

✅ 0 Failed, 121709 Passed, 56649 Skipped, 4h 26m 41.92s Total duration (5h 29m 5.07s time saved)

@mabdinur mabdinur closed this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant