Appium Server Stops Forcefully When Start the server using Python Script

Hello Folks,

I am Facing the Appium server connection issue in the Windows system I am using Appium 2.1 and Appium Python client 3.1.1.

I am starting the Appium Server using the Python script and calling that function from the robot, But when the open application keyword starts at that time, the Appium server stops forcefully and gives this error ProtocolError: (‘Connection aborted.’, ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote host’, None, 10054, None))

Function to start the Appium server
def startAppiumServer(self,portNum):
try:
port = int(portNum)
with open(os.devnull, ‘w’) as FNULL:
command = “appium -p {0} --base-path /wd/hub”.format(port)
process = subprocess.Popen(command, shell=True, stderr=FNULL, stdout=subprocess.PIPE)
while True:
output = process.stdout.readline().decode(“UTF-8”)
if output.strip() and “started” in output:
time.sleep(3) # Add a delay for the server to fully start
return True
except ValueError:
print(“Error: Invalid port number”)
except Exception as err:
print(“Error: Start Appium Server Failed -”, err)
return False

Note: The server keeps running when start the server manually

There must be something wrong with the above script. Try to use AppiumService instead to run the server