Skip to content

Commit

Permalink
Fix an issue in startup lifespan
Browse files Browse the repository at this point in the history
  • Loading branch information
AliRn76 committed Mar 25, 2024
1 parent 9808592 commit 7bde013
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/docs/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 4.0.1
- Fix an issue in `startup` lifespan

### 4.0.0
- Move `database` and `redis` connections from `MIDDLEWARES` to their own block, `DATABASE` and `REDIS`
- Make `Database` queries `async`
Expand Down
2 changes: 1 addition & 1 deletion panther/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from panther.main import Panther # noqa: F401

__version__ = '4.0.0'
__version__ = '4.0.1'


def version():
Expand Down
7 changes: 3 additions & 4 deletions panther/base_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ async def start(self):
but they have same Manager()
"""

if config.HAS_WS:
# Schedule the async function to run in the background,
# We don't need to await for this task
asyncio.create_task(self())
# Schedule the async function to run in the background,
# We don't need to await for this task
asyncio.create_task(self())

@classmethod
async def handle_authentication(cls, connection: Websocket):
Expand Down
3 changes: 2 additions & 1 deletion panther/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ async def __call__(self, scope: dict, receive: Callable, send: Callable) -> None
if scope['type'] == 'lifespan':
message = await receive()
if message["type"] == 'lifespan.startup':
await config.WEBSOCKET_CONNECTIONS.start()
if config.HAS_WS:
await config.WEBSOCKET_CONNECTIONS.start()
await Event.run_startups()
elif message["type"] == 'lifespan.shutdown':
# It's not happening :\, so handle the shutdowns in __del__ ...
Expand Down

0 comments on commit 7bde013

Please sign in to comment.