Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docstrings and minor fixes server #3082

Merged
merged 4 commits into from
Apr 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions lib/cylc/network/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ZMQServer(object):
"""

RECV_TIMEOUT = 1
"""Max time the ZMQServer will wait for an incomming message in seconds.
"""Max time the ZMQServer will wait for an incoming message in seconds.

We use a timeout here so as to give the _listener a chance to respond to
requests (i.e. stop) from its spawner (the scheduler).
Expand All @@ -75,6 +75,7 @@ class ZMQServer(object):

def __init__(self, encode_method, decode_method, secret_method):
self.port = None
self.context = zmq.Context()
self.socket = None
self.endpoints = None
self.thread = None
Expand All @@ -84,15 +85,15 @@ def __init__(self, encode_method, decode_method, secret_method):
self.secret = secret_method

def start(self, min_port, max_port):
"""Start the server running
"""Start the server running.

Args:
ports (iterable): Generator of ports (int) to choose from.
The lowest available port will be chosen.
Will use a port range provided to select random ports.

Args:
min_port (int): minimum socket port number
max_port (int): maximum socket port number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: we should make the site configuration more compatible with this, doing min(ports), max(ports) is wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puted to #2978

"""
# create socket
self.context = zmq.Context()
self.socket = self.context.socket(zmq.REP)
self.socket.RCVTIMEO = int(self.RECV_TIMEOUT) * 1000

Expand All @@ -103,7 +104,7 @@ def start(self, min_port, max_port):
self.register_endpoints()

self.queue = Queue()
# TODO: this in asyncio? Requires the Cylc main loop in ascyncio first
# TODO: this in asyncio? Requires the Cylc main loop in asyncio first
self.thread = Thread(target=self._listener)
self.thread.start()

Expand All @@ -123,7 +124,7 @@ def register_endpoints(self):
def _listener(self):
"""The server main loop, listen for and serve requests."""
while True:
# process any commands passed to the listner by its parent process
# process any commands passed to the listener by its parent process
if self.queue.qsize():
command = self.queue.get()
if command == 'STOP':
Expand Down Expand Up @@ -161,7 +162,11 @@ def _listener(self):
sleep(0) # yield control to other threads

def _receiver(self, message):
"""Wrap incoming messages and dispatch them to exposed methods."""
"""Wrap incoming messages and dispatch them to exposed methods.

Args:
message (dict): message contents
"""
# determine the server method to call
try:
method = getattr(self, message['command'])
Expand Down Expand Up @@ -556,6 +561,8 @@ def get_task_requisites(self, task_globs=None, list_prereqs=False):
Args:
task_globs (list, optional):
List of identifiers, see `task globs`_
list_prereqs (bool): whether to include the prerequisites in
the results or not.

Returns:
list: Dictionary of `task identifiers <task identifier>`_
Expand Down Expand Up @@ -636,7 +643,7 @@ def identify(self):
cylc.suite_status.KEY_OWNER
The user account the suite is running under.
cylc.suite_status.KEY_VERSION
The Cylc version the suite is runnin with.
The Cylc version the suite is running with.

"""
return {
Expand Down