generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from dvonthenen/restructure-common-test-cases
Examples to Demonstrate KeepAlive and Failure for Not Using It
- Loading branch information
Showing
6 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -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()) |
This file contains 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 |
---|---|---|
@@ -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() |
File renamed without changes.
File renamed without changes.
This file contains 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 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