Skip to content

Commit 9b353e9

Browse files
committed
Fix "There is no current event loop" error in auth module
Fix #1273
1 parent 8c372de commit 9b353e9

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class NopeLock(object):
2+
def __enter__(self):
3+
pass
4+
5+
def __exit__(self, *args):
6+
pass
7+
8+
9+
class AsyncNopeLock(object):
10+
async def __aenter__(self):
11+
pass
12+
13+
async def __aexit__(self, *args):
14+
pass

sdk/python/packages/flet-core/src/flet_core/page.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from flet_core.event import Event
2020
from flet_core.event_handler import EventHandler
2121
from flet_core.floating_action_button import FloatingActionButton
22+
from flet_core.locks import AsyncNopeLock, NopeLock
2223
from flet_core.navigation_bar import NavigationBar
2324
from flet_core.protocol import Command
2425
from flet_core.querystring import QueryString
@@ -64,22 +65,6 @@ def __init__(self, pubsubhub, session_id) -> None:
6465
from typing_extensions import Literal
6566

6667

67-
class NopeLock(object):
68-
def __enter__(self):
69-
pass
70-
71-
def __exit__(self, *args):
72-
pass
73-
74-
75-
class AsyncNopeLock(object):
76-
async def __aenter__(self):
77-
pass
78-
79-
async def __aexit__(self, *args):
80-
pass
81-
82-
8368
class Page(Control):
8469
"""
8570
Page is a container for `View` (https://flet.dev/docs/controls/view) controls.

sdk/python/packages/flet/src/flet/auth/authorization.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from flet.auth.oauth_token import OAuthToken
1111
from flet.auth.user import User
1212
from flet.version import version
13+
from flet_core.locks import AsyncNopeLock, NopeLock
14+
from flet_core.utils import is_asyncio
1315
from oauthlib.oauth2 import WebApplicationClient
1416
from oauthlib.oauth2.rfc6749.tokens import OAuth2Token
1517

@@ -28,8 +30,8 @@ def __init__(
2830
self.provider = provider
2931
self.__token: Optional[OAuthToken] = None
3032
self.user: Optional[User] = None
31-
self.__lock = threading.Lock()
32-
self.__async_lock = asyncio.Lock()
33+
self.__lock = threading.Lock() if not is_asyncio() else NopeLock()
34+
self.__async_lock = asyncio.Lock() if is_asyncio() else AsyncNopeLock()
3335

3436
# fix scopes
3537
self.scope.extend(self.provider.scopes)

sdk/python/packages/flet/src/flet/pubsub.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
from typing import Any, Callable, Dict, Iterable
55

66
import flet
7+
from flet_core.locks import AsyncNopeLock, NopeLock
8+
from flet_core.utils import is_asyncio
79

810
logger = logging.getLogger(flet.__name__)
911

1012

1113
class PubSubHub:
1214
def __init__(self):
13-
self.__lock = threading.Lock()
14-
self.__async_lock = asyncio.Lock()
15+
self.__lock = threading.Lock() if not is_asyncio() else NopeLock()
16+
self.__async_lock = asyncio.Lock() if is_asyncio() else AsyncNopeLock()
1517
self.__subscribers: Dict[str, Callable] = {} # key: session_id, value: handler
1618
self.__topic_subscribers: Dict[
1719
str, Dict[str, Callable]

0 commit comments

Comments
 (0)