FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
passkit-python-quickstart/shared/grpcConnectionPooling.py at main · PassKit/passkit-python-quickstart · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PassKit
/
passkit-python-quickstart
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
passkit-python-quickstart
/
shared
/
grpcConnectionPooling.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (39 loc) · 1.47 KB
Breadcrumbs
passkit-python-quickstart
/
shared
/
grpcConnectionPooling.py
Copy path
File metadata and controls
46 lines (39 loc) · 1.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
41
42
43
44
45
46
# shared/grpcConnectionPooling.py
import
threading
from
pathlib
import
Path
import
grpc
from
passkit
.
io
.
member
import
a_rpc_pb2_grpc
as
member_grpc
from
passkit
.
io
.
single_use_coupons
import
a_rpc_pb2_grpc
as
coupons_grpc
from
passkit
.
io
.
core
import
a_rpc_templates_pb2_grpc
as
templates_grpc
from
passkit
.
io
.
event_tickets
import
a_rpc_pb2_grpc
as
events_grpc
from
passkit
.
io
.
flights
import
a_rpc_pb2_grpc
as
flights_grpc
import
threading
import
grpc
from
pathlib
import
Path
import
constants
def
_credentials
()
->
grpc
.
ChannelCredentials
:
with
open
(
constants
.
CA_FILE
,
"rb"
)
as
f
:
ca
=
f
.
read
()
with
open
(
constants
.
CERT_FILE
,
"rb"
)
as
f
:
cert
=
f
.
read
()
with
open
(
constants
.
KEY_FILE
,
"rb"
)
as
f
:
key
=
f
.
read
()
return
grpc
.
ssl_channel_credentials
(
root_certificates
=
ca
,
private_key
=
key
,
certificate_chain
=
cert
)
class
ChannelPool
:
def
__init__
(
self
,
size
:
int
=
constants
.
POOL_SIZE
):
self
.
_lock
=
threading
.
Lock
()
self
.
_idx
=
0
creds
=
_credentials
()
self
.
_channels
=
[
grpc
.
secure_channel
(
constants
.
GRPC_HOST
,
creds
)
for
_
in
range
(
size
)]
def
get
(
self
)
->
grpc
.
Channel
:
with
self
.
_lock
:
ch
=
self
.
_channels
[
self
.
_idx
]
self
.
_idx
=
(
self
.
_idx
+
1
)
%
len
(
self
.
_channels
)
return
ch
def
close
(
self
):
for
ch
in
self
.
_channels
:
ch
.
close
()
self
.
_channels
.
clear
()
Back
|
FazBrowse Home
|
New Git URL