@@ -101,12 +101,22 @@ def server_port(self):
101
101
"""
102
102
return self ._server .server_address [1 ]
103
103
104
+ def activate (self ):
105
+ """Bind port and activate the server but do not yet start serving.
106
+
107
+ :return Port number that the server is going to use. This is the
108
+ actual port to use, even if the initially given port is 0.
109
+ """
110
+ return self ._server .activate ()
111
+
104
112
def serve (self , log = True ):
105
113
"""Start the server and wait for it to be stopped.
106
114
107
115
:param log: When ``True``, print messages about start and stop to
108
116
the console.
109
117
118
+ Automatically activates the server if it is not activated already.
119
+
110
120
If this method is executed in the main thread, automatically registers
111
121
signals SIGINT, SIGTERM and SIGHUP to stop the server.
112
122
@@ -186,23 +196,14 @@ def __init__(self, host, port):
186
196
self ._activated = False
187
197
self ._stopper_thread = None
188
198
189
- # TODO: Expose in Remote server itself
190
199
def activate (self ):
191
- """Activate server but do not yet start serving.
192
-
193
- Most importantly, port is bind and :attr:`server_address` contains
194
- the actual port number to use also if the initially given port is 0.
195
- """
196
200
if not self ._activated :
197
201
self .server_bind ()
198
202
self .server_activate ()
199
203
self ._activated = True
204
+ return self .server_address [1 ]
200
205
201
206
def serve (self ):
202
- """Start serving until the server is stopped.
203
-
204
- Activates the server automatically if it is not done before.
205
- """
206
207
self .activate ()
207
208
try :
208
209
self .serve_forever ()
@@ -213,6 +214,7 @@ def serve(self):
213
214
self .server_close ()
214
215
if self ._stopper_thread :
215
216
self ._stopper_thread .join ()
217
+ self ._stopper_thread = None
216
218
217
219
def stop (self ):
218
220
self ._stopper_thread = threading .Thread (target = self .shutdown )
0 commit comments