Skip to content

Examples to Demonstrate KeepAlive and Failure for Not Using It #348

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 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/edge_cases/keepalive/async/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

import asyncio
import time
import logging, verboselogs

from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions


async def main():
# for debugging
config: DeepgramClientOptions = DeepgramClientOptions(
verbose=logging.DEBUG, options={"keepalive": "true"}
)
deepgram: DeepgramClient = DeepgramClient("", config)

deepgram_connection = deepgram.listen.asynclive.v("1")

await deepgram_connection.start(LiveOptions())

# Wait for a while to simulate a long-running connection
await asyncio.sleep(600)

print("deadlock!")
try:
await deepgram_connection.finish()
finally:
print("no deadlock...")


asyncio.run(main())
35 changes: 35 additions & 0 deletions tests/edge_cases/keepalive/sync/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

import time
import logging, verboselogs

from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions


def main():
# for debugging
config: DeepgramClientOptions = DeepgramClientOptions(
verbose=logging.DEBUG, options={"keepalive": "true"}
)
deepgram: DeepgramClient = DeepgramClient("", config)
# OR
# deepgram: DeepgramClient = DeepgramClient()

deepgram_connection = deepgram.listen.live.v("1")

deepgram_connection.start(LiveOptions())

# press any key to exit
input("\n\nPress Enter to exit...\n\n")

print("deadlock!")
try:
deepgram_connection.finish()
finally:
print("no deadlock...")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@


async def main():
# for debugging
config: DeepgramClientOptions = DeepgramClientOptions(verbose=logging.DEBUG)
deepgram: DeepgramClient = DeepgramClient("", config)
# OR
# deepgram: DeepgramClient = DeepgramClient()

deepgram_connection = deepgram.listen.asynclive.v("1")

await deepgram_connection.start(LiveOptions())

time.sleep(
30
) # Deepgram will close the connection after 10-15s of silence, followed with another 5 seconds for a ping
# Deepgram will close the connection after 10-15s of silence, followed with another 5 seconds for a ping
await asyncio.sleep(30)

print("deadlock!")
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@


def main():
config: DeepgramClientOptions = DeepgramClientOptions(verbose=logging.DEBUG)
# for debugging
config: DeepgramClientOptions = DeepgramClientOptions(verbose=logging.SPAM)
deepgram: DeepgramClient = DeepgramClient("", config)
# OR
# deepgram: DeepgramClient = DeepgramClient()

deepgram_connection = deepgram.listen.live.v("1")

deepgram_connection.start(LiveOptions())

time.sleep(
30
) # Deepgram will close the connection after 10-15s of silence, followed with another 5 seconds for a ping
# Deepgram will close the connection after 10-15s of silence, followed with another 5 seconds for a ping
time.sleep(30)

print("deadlock!")
try:
Expand Down