Skip to content

Commit

Permalink
update ssh interface + config file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchiLaser committed May 8, 2024
1 parent ec97ff4 commit c50f2ee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
3 changes: 1 addition & 2 deletions config/example_task.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
woking_directory = "~" # working directory of the running process
environment = "venv" # activate virtual environment relative to working directory
output = "output" # redirect stdout of all processes |
error = "error" # redirect stderr of all processes \- into files in a directory relative to working directory
output = "fib_run" # redirect stdout and stderr of all processes into files, relative to working directory
assign = "assignments.csv" # file containing the assignments for the runs with their numbers
executable = "python fib.py" # executable file relative to working directory
fix_arguments = "" # Arguments which are always the same for every run
Expand Down
3 changes: 1 addition & 2 deletions src/pisa/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
__version__ = "0.1.1"
__version__ = "0.1.2"

# a list of all the keys which have to be present in the task configuration file
task_necessary_keys = {
"woking_directory",
"environment",
"output",
"assign",
"error",
"executable",
"var_arguments"
}
Expand Down
4 changes: 2 additions & 2 deletions src/pisa/dispatcher/task_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def fill_queue(task_queue: queue.Queue, config: dict, add_args: list[running_var
args=current_args, # the shlex.split() function transforms a string containing a collection of arguments into a list of single arguments
w_dir=config['woking_directory'],
env=config['environment'],
out=config['output'],
err=config['error'],
out=f"{config['output']}/stdout",
err=f"{config['output']}/stderr",
))
# write the task with its parameters and the corresponding number into the assignment file
assignto.write(f"{num}, {config['executable']} {current_args}\n")
Expand Down
21 changes: 5 additions & 16 deletions src/pisa/ssh/ssh.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

import fcntl
import os
import subprocess

Expand All @@ -19,13 +18,9 @@ def connect(self):
stderr=subprocess.PIPE,
)

# weird hack to transform stdout and stderr into other fds where reading is non blocking
# first get the file descriptors of the pipes
# then use the fcntl system call to change the file descriptor flags
stdout_fd = self.ssh_process.stdout.fileno()
stderr_fd = self.ssh_process.stderr.fileno()
fcntl.fcntl(stdout_fd, fcntl.F_SETFL, os.O_NONBLOCK)
fcntl.fcntl(stderr_fd, fcntl.F_SETFL, os.O_NONBLOCK)
# set stdout and stderr to non blocking read mode
os.set_blocking(self.ssh_process.stdout.fileno(), False)
os.set_blocking(self.ssh_process.stderr.fileno(), False)

return self # monadic return

Expand All @@ -41,17 +36,11 @@ def send_command(self, command):

def read_stdout(self):
self._check_connected()
try:
return self.ssh_process.stdout.read1().decode('utf-8')
except BlockingIOError:
return None
return self.ssh_process.stdout.read1().decode('utf-8')

def read_stderr(self):
self._check_connected()
try:
return self.ssh_process.stderr.read1().decode('utf-8')
except BlockingIOError:
return None
return self.ssh_process.stderr.read1().decode('utf-8')

def wait(self):
self._check_connected()
Expand Down

0 comments on commit c50f2ee

Please sign in to comment.