robotframework icon indicating copy to clipboard operation
robotframework copied to clipboard

run robot with multi thread has error: [ ERROR ] Reading XML source 'D:\result\output.xml' failed: Incompatible child element 'statistics' for 'kw'.

Open ysy1418899560 opened this issue 1 year ago • 1 comments

robotframework: 6.1.1 python: 3.7.9

hello, when I run robot with multi thread has error: [ ERROR ] Reading XML source 'D:\result\output.xml' failed: Incompatible child element 'statistics' for 'kw'. I start 4 threads to execute run(robot_file_path, outputdir=result_path) at the same time, i get a error message: [ ERROR ] Reading XML source 'D:\result\output.xml' failed: Incompatible child element 'statistics' for 'kw'.

Uploading DD97FFE0-905C-417e-8E06-F68FBCB0C133.png…

below is my code script:

import threading

from robot import run

class MultiThreadings(object):

def __init__(self):
    self.thread = threading

def run(self, robot_file_path, result_path):
    run(robot_file_path, outputdir=result_path)
    threading_id_str = "thread" + str(self.thread.get_ident())

def multi(self, robot_file_path, result_path):
    threads = []
    for i in range(0, 4):
        t = self.thread.Thread(target=self.run, args=(robot_file_path, result_path + "-" + str(i)))
        threads.append(t)
    for t in threads:
        t.start()

robot_file_path = "./01.robot" result_path = "./result" multi = MultiThreadings() multi.multi(robot_file_path, result_path) print("ok")

ysy1418899560 avatar Jan 18 '24 08:01 ysy1418899560

I've had the same problem many times. The robot.api.logger is not thread-safe, you should not call it from different threads, only the MainThread. I'm considering creating a monkeypatch to add a mutex over it.

Lenormju avatar Feb 20 '24 16:02 Lenormju