I can't import
because it automatically makes the threaded file run and that stops the main file from running. I need to access a variable from the client file. I am writing this code for a robot and I really need to be able to access the variables from the client.
import serial
import serial.tools.list_ports as list_ports
import time
import threading
from subprocess import call
x = ""
def thread_second():
call(["python3", "client.py"])
processThread = threading.Thread(target=thread_second)
processThread.start()
def getch():
import sys, tty, termios
old_settings = termios.tcgetattr(0)
new_settings = old_settings[:]
new_settings[3] &= ~termios.ICANON
try:
termios.tcsetattr(0, termios.TCSANOW, new_settings)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(0, termios.TCSANOW, old_settings)
return ch
if __name__ == '__main__':
port_data = list_ports.comports()
ser = serial.Serial("/dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_758333530353514112B1-if00", 115200, timeout=0)
ser.flush()
print(port_data)
while True:
previous = x
x = getch()
x = x + "\n"
ser.write(x.encode())