Skip to content

Commit c601e75

Browse files
Merge pull request #348 from dvonthenen/restructure-common-test-cases
Examples to Demonstrate KeepAlive and Failure for Not Using It
2 parents 95e2b81 + 2224bb8 commit c601e75

File tree

6 files changed

+79
-7
lines changed

6 files changed

+79
-7
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
2+
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
3+
# SPDX-License-Identifier: MIT
4+
5+
import asyncio
6+
import time
7+
import logging, verboselogs
8+
9+
from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions
10+
11+
12+
async def main():
13+
# for debugging
14+
config: DeepgramClientOptions = DeepgramClientOptions(
15+
verbose=logging.DEBUG, options={"keepalive": "true"}
16+
)
17+
deepgram: DeepgramClient = DeepgramClient("", config)
18+
19+
deepgram_connection = deepgram.listen.asynclive.v("1")
20+
21+
await deepgram_connection.start(LiveOptions())
22+
23+
# Wait for a while to simulate a long-running connection
24+
await asyncio.sleep(600)
25+
26+
print("deadlock!")
27+
try:
28+
await deepgram_connection.finish()
29+
finally:
30+
print("no deadlock...")
31+
32+
33+
asyncio.run(main())
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
2+
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import logging, verboselogs
7+
8+
from deepgram import DeepgramClient, DeepgramClientOptions, LiveOptions
9+
10+
11+
def main():
12+
# for debugging
13+
config: DeepgramClientOptions = DeepgramClientOptions(
14+
verbose=logging.DEBUG, options={"keepalive": "true"}
15+
)
16+
deepgram: DeepgramClient = DeepgramClient("", config)
17+
# OR
18+
# deepgram: DeepgramClient = DeepgramClient()
19+
20+
deepgram_connection = deepgram.listen.live.v("1")
21+
22+
deepgram_connection.start(LiveOptions())
23+
24+
# press any key to exit
25+
input("\n\nPress Enter to exit...\n\n")
26+
27+
print("deadlock!")
28+
try:
29+
deepgram_connection.finish()
30+
finally:
31+
print("no deadlock...")
32+
33+
34+
if __name__ == "__main__":
35+
main()
File renamed without changes.
File renamed without changes.

tests/expected_failures/async_live_timeout/main.py renamed to tests/expected_failures/exercise_timeout/async/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010

1111

1212
async def main():
13+
# for debugging
1314
config: DeepgramClientOptions = DeepgramClientOptions(verbose=logging.DEBUG)
1415
deepgram: DeepgramClient = DeepgramClient("", config)
16+
# OR
17+
# deepgram: DeepgramClient = DeepgramClient()
1518

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

1821
await deepgram_connection.start(LiveOptions())
1922

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

2426
print("deadlock!")
2527
try:

tests/expected_failures/sync_live_timeout/main.py renamed to tests/expected_failures/exercise_timeout/sync/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010

1111
def main():
12-
config: DeepgramClientOptions = DeepgramClientOptions(verbose=logging.DEBUG)
12+
# for debugging
13+
config: DeepgramClientOptions = DeepgramClientOptions(verbose=logging.SPAM)
1314
deepgram: DeepgramClient = DeepgramClient("", config)
15+
# OR
16+
# deepgram: DeepgramClient = DeepgramClient()
1417

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

1720
deepgram_connection.start(LiveOptions())
1821

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

2325
print("deadlock!")
2426
try:

0 commit comments

Comments
 (0)