Sha256: 1cab1accfd2b4e0f793e2256c92208b2e620d023c6dc79caca5e8ba7791aa5ce
Contents?: true
Size: 1 KB
Versions: 23
Compression:
Stored size: 1 KB
Contents
# frozen_string_literal: true module OhlohScm class PyClient def start @stdin, @stdout, @stderr, wait_thr = Open3.popen3 "python #{@py_script}" @pid = wait_thr[:pid] open_repository end def shutdown send_command('QUIT') [@stdin, @stdout, @stderr].reject(&:closed?).each(&:close) Process.waitpid(@pid, Process::WNOHANG) end private def send_command(cmd) # send the command @stdin.puts cmd @stdin.flush return if cmd == 'QUIT' # get status on stderr, first letter indicates state, # remaing value indicates length of the file content status = @stderr.read(10) flag = status[0, 1] size = status[1, 9].to_i return if flag == 'F' raise_subprocess_error(flag) # read content from stdout @stdout.read(size) end def raise_subprocess_error(flag) return unless flag == 'E' error = @stdout.read(size) raise "Exception in server process\n#{error}" end end end
Version data entries
23 entries across 23 versions & 1 rubygems
Version | Path |
---|---|
ohloh_scm-3.0.3 | lib/ohloh_scm/py_bridge/py_client.rb |
ohloh_scm-3.0.2 | lib/ohloh_scm/py_bridge/py_client.rb |
ohloh_scm-3.0.1 | lib/ohloh_scm/py_bridge/py_client.rb |