Skip to content

Commit

Permalink
If <3.7 and no get_running_loop, return false. (#107)
Browse files Browse the repository at this point in the history
Some people have contextvars backported, so it's no longer a useful 3.7 canary; instead just probe directly for the method we use.
  • Loading branch information
lizthegrey authored Mar 24, 2020
1 parent ed337a9 commit 7f9b1fa
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions beeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

try:
import asyncio
# The async functionality uses the contextvars module, added in
# Python 3.7
import contextvars
assert contextvars
try:
asyncio.get_running_loop() # pylint: disable=no-member
except RuntimeError:
pass

from beeline.aiotrace import AsyncioTracer, traced_impl, untraced
assert untraced

def in_async_code():
"""Return wether we are running inside an asynchronous task.
"""Return whether we are running inside an asynchronous task.
We use this information to determine which tracer
implementation to use.
Expand All @@ -42,9 +42,8 @@ def in_async_code():
except RuntimeError:
return False

except ImportError:
# Use these non-async versions if we don't have asyncio or
# contextvars.
except (ImportError, AttributeError):
# Use these non-async versions if we don't have asyncio.
from beeline.trace import traced_impl

def in_async_code():
Expand Down

0 comments on commit 7f9b1fa

Please sign in to comment.