-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy path__main__.py
More file actions
40 lines (36 loc) · 1.34 KB
/
__main__.py
File metadata and controls
40 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
import argparse
import asyncio
import logging
from basic_example import run as run_sync
from basic_example_async import run as run_async
if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""\033[92mYDB basic example.\x1b[0m\n""",
)
parser.add_argument("-e", "--endpoint", help="Endpoint url to use", default="grpc://localhost:2136")
parser.add_argument("-d", "--database", help="Name of the database to use", default="/local")
parser.add_argument("-v", "--verbose", default=False, action="store_true")
parser.add_argument("-m", "--mode", default="sync", help="Mode of example: sync or async")
args = parser.parse_args()
if args.verbose:
logger = logging.getLogger("ydb.pool.Discovery")
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
if args.mode == "sync":
print("Running sync example")
run_sync(
args.endpoint,
args.database,
)
elif args.mode == "async":
print("Running async example")
asyncio.run(
run_async(
args.endpoint,
args.database,
)
)
else:
raise ValueError(f"Unsupported mode: {args.mode}, use one of sync|async")