Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
715d5090
Commit
715d5090
authored
Apr 02, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ssh_connect wrapped to make it non-blocking
parent
c549a01b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
main.py
main.py
+21
-3
No files found.
main.py
View file @
715d5090
...
...
@@ -2,13 +2,16 @@ import io
import
logging
import
os.path
import
socket
import
threading
import
traceback
import
uuid
import
weakref
import
paramiko
import
tornado.gen
import
tornado.ioloop
import
tornado.web
import
tornado.websocket
from
tornado.concurrent
import
Future
from
tornado.ioloop
import
IOLoop
from
tornado.iostream
import
_ERRNO_CONNRESET
from
tornado.options
import
define
,
options
,
parse_command_line
...
...
@@ -222,19 +225,34 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
IOLoop
.
current
()
.
call_later
(
DELAY
,
recycle
,
worker
)
return
worker
def
ssh_connect_wrapped
(
self
,
future
):
try
:
worker
=
self
.
ssh_connect
()
except
Exception
as
exc
:
future
.
set_exception
(
exc
)
raise
exc
else
:
future
.
set_result
(
worker
)
def
get
(
self
):
self
.
render
(
'index.html'
)
@tornado.gen.coroutine
def
post
(
self
):
worker_id
=
None
status
=
None
future
=
Future
()
try
:
worker
=
self
.
ssh_connect
()
except
Exception
as
e
:
threading
.
Thread
(
target
=
self
.
ssh_connect_wrapped
,
args
=
(
future
,)
)
.
start
()
yield
future
except
Exception
as
exc
:
logging
.
error
(
traceback
.
format_exc
())
status
=
str
(
e
)
status
=
str
(
e
xc
)
else
:
worker
=
future
.
result
()
worker
.
src_addr
=
self
.
get_client_addr
()
worker_id
=
worker
.
id
workers
[
worker_id
]
=
worker
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment