Running robot keywords in multiple threads

2,194 views
Skip to first unread message

Raphael Castaneda

unread,
Jun 3, 2013, 8:10:02 PM6/3/13
to robotframe...@googlegroups.com
I've come across a few cases I would like to test that require the test performing multiple actions simultaneously.
In most cases, it is sufficient to start one or more tasks and check their output. However, it would nice to be able to use multiple threads.

To experiment with this, I wrote a small library that spawns new threads to run arbitrary keywords in the background, and allows the main thread to wait for the background tasks to finish (using thread.join())
The keyword to run is passed in as a parameter, and robot's BuiltIn library is used to resolve and run the specified keyword.

Right away, I ran into two issues:
  1. Log messages generated by background threads will get scrambled into the main thread's output
  2. Starting and ending keywords outside of the main thread causes a strange ValueError
ValueError: I/O operation on closed file
Traceback (most recent call last):
  File "C:\RobotAsyncLibrary.py", line 58, in wait_for_background_keywords
    thread.join(timeout=timeout)
  File "C:\Python27\lib\StringIO.py", line 213, in write
    _complain_ifclosed(self.closed)
  File "C:\Python27\lib\StringIO.py", line 40, in _complain_ifclosed
    raise ValueError, "I/O operation on closed file"

I think the 2nd problem arises because the keywords in the background are closing the stream to the log file(s) when they finish.
This is probably just a limitation inherent in Robot, but I figured it was worth asking. Is there a way around this?
RobotAsyncLibrary.py

Raphael Castaneda

unread,
Jun 3, 2013, 8:16:58 PM6/3/13
to robotframe...@googlegroups.com
Note: in the attached version of the library, there's a wild Try/Except block hiding the exception.

Pekka Klärck

unread,
Jun 4, 2013, 3:12:35 PM6/4/13
to raphael....@gmail.com, robotframe...@googlegroups.com
2013/6/4 Raphael Castaneda <raphael....@gmail.com>:
> I've come across a few cases I would like to test that require the test
> performing multiple actions simultaneously.
> In most cases, it is sufficient to start one or more tasks and check their
> output. However, it would nice to be able to use multiple threads.
>
> To experiment with this, I wrote a small library that spawns new threads to
> run arbitrary keywords in the background, and allows the main thread to wait
> for the background tasks to finish (using thread.join())
> The keyword to run is passed in as a parameter, and robot's BuiltIn library
> is used to resolve and run the specified keyword.
>
> Right away, I ran into two issues:
>
> Log messages generated by background threads will get scrambled into the
> main thread's output
> Starting and ending keywords outside of the main thread causes a strange
> ValueError

Using threads like this is not supported. As explained in the User
Guide, only the main thread should communicate with the framework:
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#communication-when-using-threads

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages