Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e14e616
Apparently working w/ time conversions
taldcroft Dec 30, 2022
c0b7b7b
Vectorize date2time for backstop
taldcroft Dec 30, 2022
c552e4c
Apply black/isort to utils.py
taldcroft Dec 30, 2022
d6450f4
Running to completion
taldcroft Dec 30, 2022
a795acc
Remove final INLINE refs (env vars)
taldcroft Dec 30, 2022
dce71d8
Minor cleanup
taldcroft Dec 30, 2022
58c11e3
Get free port and secure comm w/ key
taldcroft Dec 31, 2022
b7aeb60
Add functionality to collect call statistics
taldcroft Dec 31, 2022
a4f57d9
Reduce some Python calls and cut unused processing
taldcroft Dec 31, 2022
38beb17
No limit on number of obsids
taldcroft Dec 31, 2022
4ada1e6
Vectorize yagzag_to_pixels call
taldcroft Jan 1, 2023
d6087bd
Don't call pixel_to_yagzag for bad pixels
taldcroft Jan 1, 2023
c95b910
More performance and code tidy
taldcroft Jan 1, 2023
79c351f
Start server in the main starcheck process (don't fork)
taldcroft Jan 5, 2023
86c39d6
Add a server timeout (probably not needed?)
taldcroft Jan 5, 2023
69105ce
More verbose server timeout text
jeanconn Jan 5, 2023
dc8a6b6
Put GetOptions earlier in the code
jeanconn Jan 5, 2023
3cc1cf4
Only show server calls if verbose > 1
jeanconn Jan 5, 2023
7f73242
Put usage() right after GetOptions
jeanconn Jan 5, 2023
9a54ead
Set max_obsids by cmdline option
jeanconn Jan 5, 2023
05a1002
Update dither parsing comments
jeanconn Jan 5, 2023
bed6674
If we have two dither errors, keep them.
jeanconn Jan 5, 2023
5bc68f0
Remove unused Dumper import
jeanconn Jan 5, 2023
1011893
Increase server timeout to 180s
jeanconn Jan 5, 2023
2d35131
Change check on kadi log level to be gt
jeanconn Jan 5, 2023
c5ea583
Use Dumper instead of Dump
jeanconn Jan 5, 2023
d719afd
Configure output to work with -verbose
jeanconn Jan 5, 2023
dec5dbb
Add help for verbosity
jeanconn Jan 5, 2023
5be93b4
Fix guide summ bug introduced in #389
jeanconn Jan 5, 2023
65ae9aa
Remove defunct decode()s
jeanconn Jan 6, 2023
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
34 changes: 24 additions & 10 deletions starcheck/server.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import collections
import importlib
import json
import logging
import socketserver
import sys
import traceback

from ska_helpers.logging import basic_logger

logger = basic_logger(__name__, level="INFO")

HOST = "localhost"
KEY = None

Expand Down Expand Up @@ -33,18 +38,18 @@ class MyTCPHandler(socketserver.StreamRequestHandler):
def handle(self):
# self.request is the TCP socket connected to the client
data = self.rfile.readline()
# print(f"SERVER receive: {data.decode('utf-8')}")
logger.debug(f"SERVER receive: {data.decode('utf-8')}")

# Decode self.data from JSON
cmd = json.loads(data)

if cmd["key"] != KEY:
print(f"SERVER: bad key {cmd['key']!r}")
logger.ERROR(f"SERVER: bad key {cmd['key']!r}")
return

# print(f"SERVER receive func: {cmd['func']}")
# print(f"SERVER receive args: {cmd['args']}")
# print(f"SERVER receive kwargs: {cmd['kwargs']}")
logger.debug(f"SERVER receive func: {cmd['func']}")
logger.debug(f"SERVER receive args: {cmd['args']}")
logger.debug(f"SERVER receive kwargs: {cmd['kwargs']}")

exc = None

Expand All @@ -69,20 +74,29 @@ def handle(self):
exc = traceback.format_exc()

resp = json.dumps({"result": result, "exception": exc})
# print(f"SERVER send: {resp}")
logger.debug(f"SERVER send: {resp}")

self.request.sendall(resp.encode("utf-8"))


def main():
global KEY

# Read a line from STDIN
port = int(sys.stdin.readline().strip())
KEY = sys.stdin.readline().strip()

print("SERVER: starting on port", port)

loglevel = sys.stdin.readline().strip()

logmap = {'0': logging.CRITICAL,
Comment thread
jeanconn marked this conversation as resolved.
'1': logging.WARNING,
'2': logging.INFO}
if loglevel in logmap:
logger.setLevel(logmap[loglevel])
if int(loglevel) > 2:
logger.setLevel(logging.DEBUG)

logger.info(f"SERVER: starting on port {port}")

# Create the server, binding to localhost on supplied port
with PythonServer((HOST, port), MyTCPHandler) as server:
# Activate the server; this will keep running until you
Expand Down
17 changes: 12 additions & 5 deletions starcheck/src/lib/Ska/Starcheck/Python.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ $Data::Dumper::Terse = 1;
my $HOST = "localhost";
my $PORT = 40000;
my $KEY = "fff";
my $VERBOSE = 1;

sub set_port {
$PORT = shift;
print "CLIENT: Setting port to $PORT\n";
}

sub set_key {
$KEY = shift;
print "CLIENT: Setting key to $KEY\n";
}

sub set_debug {
$VERBOSE = shift;
}

sub call_python {
Expand All @@ -47,8 +50,10 @@ sub call_python {
"key" => $KEY,
};
my $command_json = encode_json $command;
# print "CLIENT: Sending command $command_json\n";

if ($VERBOSE gt 2){
print STDERR "CLIENT: Sending command $command_json\n";
}
my $handle;
my $iter = 0;
while ($iter++ < 10) {
Expand All @@ -68,8 +73,10 @@ sub call_python {
$handle->close();

my $data = decode_json $response;
# print "CLIENT: Got response: $response\n";
# print Dumper($data);
if ($VERBOSE gt 2){
print STDERR "CLIENT: Got response: $response\n";
print STDERR Dumper($data);
}
if (defined $data->{exception}) {
my $msg = "\nPython exception:\n";
$msg .= "command = " . Dumper($command) . "\n";
Expand Down
14 changes: 11 additions & 3 deletions starcheck/src/starcheck.pl
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@
# Configure the Python interface
Ska::Starcheck::Python::set_port($server_port);
Ska::Starcheck::Python::set_key($server_key);
Ska::Starcheck::Python::set_debug($par{verbose});
if ($par{verbose} gt 1){
print STDERR "CLIENT: starcheck.server started on port $server_port\n";
print STDERR "CLIENT: starcheck.server key $server_key\n";
}

# Start a server that can call functions in the starcheck package
my $pid = open(SERVER, "| python -m starcheck.server");
SERVER->autoflush(1);
# Send the port and key to the server
# Send the port, key, and verbosity to the server
print SERVER "$server_port\n";
print SERVER "$server_key\n";
print SERVER "$par{verbose}\n";

# DEBUG, limit number of obsids.
# Set to undef for no limit (though option defaults to 0)
Expand Down Expand Up @@ -1167,8 +1173,10 @@ END
print("Python server calls:");
print Dumper($server_calls);
}
print("Shutting down python starcheck server with pid=$pid\n");
kill 9, $pid; # must it be 9 (SIGKILL)?
if ($par{verbose} gt 1){
print("Shutting down python starcheck server with pid=$pid\n");
}
kill 9, $pid; # must it be 9 (SIGKILL)?
my $gone_pid = waitpid $pid, 0; # then check that it's gone
}
};
Expand Down