Skip to content

Commit b45e111

Browse files
committed
Fixed signals and ctrl-c to stop the process immediately.
Fixes #10.
1 parent dbd48d6 commit b45e111

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

atest/tests/resource.robot

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ ${INTERPRETER} python
88

99
*** Keywords ***
1010
Start And Import Remote Library
11-
[Arguments] ${library}
11+
[Arguments] ${library} ${name}=Remote
1212
Set Pythonpath
1313
${port} = Start Remote Library ${library}
14-
Import Library Remote http://127.0.0.1:${port}
14+
Import Library Remote http://127.0.0.1:${port} WITH NAME ${name}
1515
Set Suite Variable ${ACTIVE PORT} ${port}
1616
Set Log Level DEBUG
1717

@@ -46,3 +46,4 @@ Server Should Be Stopped And Correct Messages Logged
4646
... Robot Framework remote server at 127.0.0.1:${ACTIVE PORT} starting.
4747
... Robot Framework remote server at 127.0.0.1:${ACTIVE PORT} stopping.
4848
Should Be Equal ${result.stdout} ${expected}
49+
Should Be Equal ${result.rc} ${0}

atest/tests/stopping.robot

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
*** Settings ***
2+
Resource resource.robot
3+
Test Setup Start Server
4+
Test Teardown Server Should Be Stopped
5+
6+
*** Test Cases ***
7+
Stop Remote Server
8+
Stop Remote Server
9+
10+
SIGINT
11+
Send Signal To Process SIGINT
12+
13+
SIGHUP
14+
Send Signal To Process SIGHUP
15+
16+
*** Keywords ***
17+
Start Server
18+
Start And Import Remote Library basics.py ${TEST NAME}
19+
Server Should Be Started
20+
21+
Server Should Be Started
22+
Run Keyword ${TEST NAME}.Passing
23+
24+
Server Should Be Stopped
25+
Server Should Be Stopped And Correct Messages Logged
26+
Run Keyword And Expect Error Connection to remote server broken: *
27+
... Server Should Be Started

src/robotremoteserver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def _register_signal_handlers(self):
6262
def stop_with_signal(signum, frame):
6363
self._allow_stop = True
6464
self.stop_remote_server()
65+
raise KeyboardInterrupt
6566
if hasattr(signal, 'SIGHUP'):
6667
signal.signal(signal.SIGHUP, stop_with_signal)
6768
if hasattr(signal, 'SIGINT'):
@@ -79,8 +80,11 @@ def _announce_start(self, port_file=None):
7980
pf.close()
8081

8182
def serve_forever(self):
82-
while not self._shutdown:
83-
self.handle_request()
83+
try:
84+
while not self._shutdown:
85+
self.handle_request()
86+
except KeyboardInterrupt:
87+
pass
8488

8589
def stop_remote_server(self):
8690
prefix = 'Robot Framework remote server at %s:%s ' % self.server_address

0 commit comments

Comments
 (0)