Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
b219338e
Commit
b219338e
authored
7 years ago
by
Craig Tiller
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #10822 from ctiller/threaded_port_server
Threaded port_server
parents
dc2e0843
ec495242
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/run_tests/python_utils/port_server.py
+18
-10
18 additions, 10 deletions
tools/run_tests/python_utils/port_server.py
with
18 additions
and
10 deletions
tools/run_tests/python_utils/port_server.py
+
18
−
10
View file @
b219338e
...
@@ -33,18 +33,20 @@
...
@@ -33,18 +33,20 @@
from
__future__
import
print_function
from
__future__
import
print_function
import
argparse
import
argparse
from
six.mo
ve
s
import
Base
HTTPServer
from
BaseHTTPSer
ve
r
import
HTTPServ
er
,
BaseHTTPRequestHandl
er
import
hashlib
import
hashlib
import
os
import
os
import
socket
import
socket
import
sys
import
sys
import
time
import
time
from
SocketServer
import
ThreadingMixIn
import
threading
# increment this number whenever making a change to ensure that
# increment this number whenever making a change to ensure that
# the changes are picked up by running CI servers
# the changes are picked up by running CI servers
# note that all changes must be backwards compatible
# note that all changes must be backwards compatible
_MY_VERSION
=
9
_MY_VERSION
=
11
if
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
'
dump_version
'
:
if
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
'
dump_version
'
:
...
@@ -68,6 +70,7 @@ print('port server running on port %d' % args.port)
...
@@ -68,6 +70,7 @@ print('port server running on port %d' % args.port)
pool
=
[]
pool
=
[]
in_use
=
{}
in_use
=
{}
mu
=
threading
.
Lock
()
def
refill_pool
(
max_timeout
,
req
):
def
refill_pool
(
max_timeout
,
req
):
...
@@ -95,28 +98,33 @@ def refill_pool(max_timeout, req):
...
@@ -95,28 +98,33 @@ def refill_pool(max_timeout, req):
def
allocate_port
(
req
):
def
allocate_port
(
req
):
global
pool
global
pool
global
in_use
global
in_use
global
mu
mu
.
acquire
()
max_timeout
=
600
max_timeout
=
600
while
not
pool
:
while
not
pool
:
refill_pool
(
max_timeout
,
req
)
refill_pool
(
max_timeout
,
req
)
if
not
pool
:
if
not
pool
:
req
.
log_message
(
"
failed to find ports: retrying soon
"
)
req
.
log_message
(
"
failed to find ports: retrying soon
"
)
mu
.
release
()
time
.
sleep
(
1
)
time
.
sleep
(
1
)
mu
.
acquire
()
max_timeout
/=
2
max_timeout
/=
2
port
=
pool
[
0
]
port
=
pool
[
0
]
pool
=
pool
[
1
:]
pool
=
pool
[
1
:]
in_use
[
port
]
=
time
.
time
()
in_use
[
port
]
=
time
.
time
()
mu
.
release
()
return
port
return
port
keep_running
=
True
keep_running
=
True
class
Handler
(
BaseHTTPServer
.
BaseHTTPRequestHandler
):
class
Handler
(
BaseHTTPRequestHandler
):
def
setup
(
self
):
def
setup
(
self
):
# If the client is unreachable for 5 seconds, close the connection
# If the client is unreachable for 5 seconds, close the connection
self
.
timeout
=
5
self
.
timeout
=
5
BaseHTTPServer
.
BaseHTTPRequestHandler
.
setup
(
self
)
BaseHTTPRequestHandler
.
setup
(
self
)
def
do_GET
(
self
):
def
do_GET
(
self
):
global
keep_running
global
keep_running
...
@@ -158,12 +166,12 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
...
@@ -158,12 +166,12 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
elif
self
.
path
==
'
/quitquitquit
'
:
elif
self
.
path
==
'
/quitquitquit
'
:
self
.
send_response
(
200
)
self
.
send_response
(
200
)
self
.
end_headers
()
self
.
end_headers
()
keep_running
=
False
sys
.
exit
(
0
)
class
ThreadedHTTPServer
(
ThreadingMixIn
,
HTTPServer
):
"""
Handle requests in a separate thread
"""
httpd
=
BaseHTTPServer
.
HTTPServer
((
''
,
args
.
port
),
Handler
)
while
keep_running
:
httpd
.
handle_request
()
sys
.
stderr
.
flush
()
print
(
'
done
'
)
httpd
=
ThreadedHTTPServer
((
''
,
args
.
port
),
Handler
)
httpd
.
serve_forever
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment