@@ -4,11 +4,11 @@ Python Remote Server for Robot Framework
44`Robot Framework `_ remote servers allow hosting test libraries on different
55processes or machines than Robot Framework itself is running on. This project
66implements a generic remote server using the Python _ programming language.
7- See the general `remote library interface documentation `_ for more information
8- about the remote interface as well as for a list of remote server
7+ See the `remote library interface documentation `_ for more information about
8+ the remote interface in general as well as for a list of remote server
99implementations in other programming languages.
1010
11- This project is hosted in GitHub _ and downloads are available in PyPI _.
11+ This project is hosted on GitHub _ and downloads are available on PyPI _.
1212
1313.. _Robot Framework : http://robotframework.org
1414.. _remote library interface documentation : https://github.com/robotframework/RemoteInterface
@@ -34,7 +34,7 @@ versions 2.2-2.7.
3434Supported library APIs
3535----------------------
3636
37- Starting from Remote server version 1.1, Robot Framework's standard `static,
37+ Starting from the remote server version 1.1, Robot Framework's `static,
3838hybrid and dynamic library APIs `__ are all supported. This includes setting
3939custom name and tags for keywords using the `robot.api.deco.keyword `__
4040decorator. Earlier versions support only the static and hybrid APIs and do
@@ -73,20 +73,14 @@ accepts the following configuration parameters when it is initialized:
7373 ===================== ================= ========================================
7474 ``library `` Test library instance or module to host. Mandatory argument.
7575 ``host `` ``'127.0.0.1' `` Address to listen. Use ``'0.0.0.0' `` to listen to all available interfaces.
76- ``port `` ``8270 `` Port to listen. Use ``0 `` to select a free port automatically. Can be given as an integer or as a string.
76+ ``port `` ``8270 `` Port to listen. Use ``0 `` to select a free port automatically. Can be given as an integer or as a string. The default port `` 8270 `` is ` registered by IANA `__ for remote server usage.
7777 ``port_file `` ``None `` File to write the port that is used. ``None `` (default) means no such file is written.
7878 ``allow_stop `` ``'DEPRECATED' `` DEPRECATED. User ``allow_remote_stop `` instead.
7979 ``serve `` ``True `` If ``True ``, start the server automatically and wait for it to be stopped. If ``False ``, server can be started using the ``serve `` method. New in version 1.1.
8080 ``allow_remote_stop `` ``True `` Allow/disallow stopping the server remotely using ``Stop Remote Server `` keyword and ``stop_remote_server `` XML-RPC method. New in version 1.1.
8181 ===================== ================= ========================================
8282
83- Address and port that are used are printed to the console where the server is
84- started. Writing port to a file by using ``port_file `` argument is especially
85- useful when the server selects a free port automatically. Other tools can then
86- easily read the active port from the file. If the file is removed prior to
87- starting the server, tools can also wait until the file exists to know that
88- the server is up and running. Starting from version 1.1, the server removes
89- the port file automatically when it is stopped.
83+ __ https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=8270
9084
9185Starting remote server
9286----------------------
@@ -110,9 +104,9 @@ __ `Remote server configuration`_
110104.. sourcecode :: python
111105
112106 from robotremoteserver import RobotRemoteServer
113- from mylibrary import MyLibrary
107+ from examplelibrary import ExampleLibrary
114108
115- RobotRemoteServer(MyLibrary (), host='10.0.0.42', port=0,
109+ RobotRemoteServer(ExampleLibrary (), host='10.0.0.42', port=0,
116110 port_file='/tmp/remote-port.txt')
117111
118112Starting from version 1.1, the server can be initialized without starting it by
@@ -122,46 +116,70 @@ equivalent to the example above:
122116
123117.. sourcecode :: python
124118
125- server = RobotRemoteServer(MyLibrary(), host='10.0.0.42', port=0,
119+ from robotremoteserver import RobotRemoteServer
120+ from examplelibrary import ExampleLibrary
121+
122+ server = RobotRemoteServer(ExampleLibrary(), host='10.0.0.42', port=0,
126123 port_file='/tmp/remote-port.txt', serve=False)
127124 server.serve()
128125
129126Starting server on background
130127-----------------------------
131128
132129The main benefit of separately initializing and starting the server is that
133- it makes it easier to start the server on a background thread. This is
134- illustrated by the following example:
130+ it makes it easier to start the server in a background thread. Servers started
131+ in a thread work exactly like servers running in the main tread except that
132+ `stopping the server `__ gracefully using ``Ctrl-C `` or signals is not
133+ supported automatically. Users must thus register signal handlers separately
134+ if needed.
135+
136+ Also this following example is functionally nearly equivalent to the earlier
137+ examples except. The main difference is that not all same signals are handled.
135138
136139.. sourcecode :: python
137140
141+ import signal
138142 import threading
139- import time
140-
143+ from examplelibrary import ExampleLibrary
141144 from robotremoteserver import RobotRemoteServer
142- from mylibrary import MyLibrary
143145
144- try:
145- raw_input
146- except NameError: # Python 3
147- raw_input = input
148-
149- # Initialize server and start it in a thread.
150- server = RobotRemoteServer(MyLibrary(), port=0, serve=False)
146+ server = RobotRemoteServer(ExampleLibrary(), port=0, serve=False)
147+ signal.signal(signal.SIGINT, lambda signum, frame: server.stop())
151148 server_thread = threading.Thread(target=server.serve)
152149 server_thread.start()
153- # Wait for server to be activated and port to be bind.
154- while server.server_port == 0:
155- time.sleep(0.1)
156- # Serve requests until user presses enter.
157- raw_input('Press enter to stop the server.\n ')
158- server.stop()
159- server_thread.join()
160-
161- Servers started this way work mostly like servers started on the main thread.
162- The main difference is that stopping the server gracefully using ``Ctrl-C ``
163- or signals is not supported automatically. The user must register signal
164- handlers separately if needed.
150+ while server_thread.is_alive():
151+ server_thread.join(0.1)
152+
153+ __ `Stopping remote server `_
154+
155+ Getting active server port
156+ --------------------------
157+
158+ If the server uses the default port ``8270 `` or some other port is given
159+ explicitly when `configuring the server `__, you obviously know which port
160+ to use when connecting the server. When using the port ``0 ``, the server
161+ selects a free port automatically, but there are various ways how to find
162+ out the actual port:
163+
164+ - Address and port that are used are printed into the console where the server
165+ is started.
166+
167+ - If ``port_file `` argument is used, the server writes the port into the
168+ specified file where other tools can easily read it. Starting from the
169+ remote server version 1.1, the server removes the port file automatically
170+ when the server is stopped.
171+
172+ - Starting from the version 1.1, the server has ``activate `` method that can
173+ be called to activate the server without starting it. This method returns
174+ the port that the server binds and also sets it available via the attributes
175+ discussed below.
176+
177+ - A started or actived server instance has ``server_address `` attribute that
178+ contains the address and the port as a tuple. Starting from the version 1.1
179+ there is also ``server_port `` attribute that contains just the port as
180+ an integer.
181+
182+ __ `Remote server configuration`__
165183
166184Stopping remote server
167185----------------------
@@ -179,18 +197,18 @@ The remote server can be gracefully stopped using several different methods:
179197 ``allow_remote_stop=False `` when `initializing the server `__.
180198
181199- Using ``stop_remote_server `` function in the XML-RPC interface.
182- Can be disabled with ``allow_remote_stop=False ``.
200+ Can be disabled with the ``allow_remote_stop=False `` initialization parameter .
183201
184202- Running ``python -m robotremoteserver stop [uri] `` which uses the
185203 aforementioned ``stop_remote_server `` XML-RPC function internally.
186- Can be disabled with ``allow_remote_stop=False ``.
204+ Can be disabled with the ``allow_remote_stop=False `` initialization parameter .
187205
188206- Using the ``stop_remote_server `` function provided by the
189207 ``robotremoteserver `` module similarly as when `testing is server running `_.
190208 Uses the ``stop_remote_server `` XML-RPC function internally and
191- can be disabled with ``allow_remote_stop=False ``.
209+ can be disabled with the ``allow_remote_stop=False `` initialization parameter .
192210
193- - Calling ``stop `` method of the running server instance. Mainly useful when
211+ - Calling the ``stop `` method of the running server instance. Mainly useful when
194212 `running the server on background `__.
195213
196214__ `Starting server on background `_
@@ -200,17 +218,17 @@ __ `Starting server on background`_
200218Testing is server running
201219-------------------------
202220
203- Starting from version 1.0.1 , the ``robotremoteserver `` module supports testing
204- is a remote server running. This can be accomplished by running the module as
205- a script with ``test `` argument and an optional URI::
221+ Starting from the version 1.0.1, the ``robotremoteserver `` module supports
222+ testing is a remote server running. This can be accomplished by running
223+ the module as a script with ``test `` argument and an optional URI::
206224
207225 $ python -m robotremoteserver test
208226 Remote server running at http://127.0.0.1:8270.
209227 $ python -m robotremoteserver test http://10.0.0.42:57347
210228 No remote server running at http://10.0.0.42:57347.
211229
212- Starting from version 1.1, ``robotremoteserver `` module contains function
213- ``test_remote_server `` that can be used programmatically:
230+ Starting from the version 1.1, the ``robotremoteserver `` module contains
231+ function ``test_remote_server `` that can be used programmatically:
214232
215233.. sourcecode :: python
216234
0 commit comments