Newer
Older
exporter / driver.py
@Mark Mark on 14 Apr 2019 763 bytes Reorg
import socket
import os
import subprocess
import sys
import threading

def get_driver_conn():
  s = socket.socket()
  s.bind(("localhost", port))

  s.settimeout(0.5)
  s.listen(0)

  return s

def get_driver_proc():
  exporter_proc_args = [os.getcwd() + "/Exporter.exe"]
  #exporter_proc_args = [os.getcwd() + "/Exporter.app/Expoter.exe", str(port)]
  return subprocess.Popen(exporter_proc_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

def get_stdin_queue():
  stdin_q = Queue.Queue()
  reader = threading.Thread(target=get_stdin, args=(stdin_q,))
  reader.daemon = True
  reader.start()
  return stdin_q

def get_stdin(stdin_q):
  while True:
    line = sys.stdin.readline()
    stdin_q.put(line)
    if line == "":
      return