-
Notifications
You must be signed in to change notification settings - Fork 42
feat: Use nest-asyncio when configured with env var #451
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,22 @@ jobs: | |
- run: make with-django2x | ||
- run: (cd .circleci/ && ./websiteDjango2x.sh) | ||
- slack/status | ||
test-website-flask-nest-asyncio: | ||
docker: | ||
- image: rishabhpoddar/supertokens_python_driver_testing | ||
resource_class: large | ||
environment: | ||
SUPERTOKENS_NEST_ASYNCIO: "1" | ||
steps: | ||
- checkout | ||
- run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2 | ||
- run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2 | ||
- run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/ | ||
- run: echo "127.0.0.1 localhost.org" >> /etc/hosts | ||
- run: make with-flask | ||
- run: python -m pip install nest-asyncio | ||
- run: (cd .circleci/ && ./websiteFlask.sh) | ||
- slack/status | ||
test-authreact-fastapi: | ||
docker: | ||
- image: rishabhpoddar/supertokens_python_driver_testing | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ | |
|
||
setup( | ||
name="supertokens_python", | ||
version="0.16.1", | ||
version="0.16.2", | ||
author="SuperTokens", | ||
license="Apache 2.0", | ||
author_email="[email protected]", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,32 @@ | |
|
||
import asyncio | ||
from typing import Any, Coroutine, TypeVar | ||
from os import getenv | ||
|
||
_T = TypeVar("_T") | ||
|
||
|
||
def check_event_loop(): | ||
def nest_asyncio_enabled(): | ||
return getenv("SUPERTOKENS_NEST_ASYNCIO", "") == "1" | ||
|
||
rishabhpoddar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure that there is at least one thing in cicd where we run the python sdk (for example in e2e test with flask), where nest_asyncio is not a dependency and then we make sure it all works |
||
def create_or_get_event_loop() -> asyncio.AbstractEventLoop: | ||
try: | ||
asyncio.get_event_loop() | ||
except RuntimeError as ex: | ||
return asyncio.get_event_loop() | ||
except Exception as ex: | ||
if "There is no current event loop in thread" in str(ex): | ||
loop = asyncio.new_event_loop() | ||
|
||
if nest_asyncio_enabled(): | ||
import nest_asyncio # type: ignore | ||
|
||
nest_asyncio.apply(loop) # type: ignore | ||
|
||
asyncio.set_event_loop(loop) | ||
return loop | ||
raise ex | ||
|
||
|
||
def sync(co: Coroutine[Any, Any, _T]) -> _T: | ||
check_event_loop() | ||
loop = asyncio.get_event_loop() | ||
loop = create_or_get_event_loop() | ||
return loop.run_until_complete(co) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.