Updates:
Summary: Document that log messages and failures from threads executed by
keywords are not visible automatically
Labels: -Type-Enhancement Type-Documentation
Comment #1 on issue 697 by pekka.klarck: Document that log messages and
failures from threads executed by keywords are not visible automatically
http://code.google.com/p/robotframework/issues/detail?id=697
Nice solution by Ossi K. below. I think it's enough if we explain the
problem and provide this solution in the User Guide.
-------8<-----------------------8<--------------------
Here is maybe a better workaround. In Java you could pipe the output
through main thread to get it to Robot logs from all threads in real time.
The same approach should work for Python too. This code implements the
workaround and also demonstrates the problem. To get all exception messages
printed also, catch Throwable in Worker's run() and print stack trace
to "out" before exiting the thread.
MyLib.java:
package com.nsn.mylib;
import java.io.PrintWriter;
import java.io.PipedWriter;
import java.io.PipedReader;
import java.io.BufferedReader;
import java.io.IOException;
public class MyLib
{
private static class Worker extends Thread
{
private final PrintWriter out;
Worker(PrintWriter out)
{
this.out = out;
}
public void run()
{
try
{
for (int i = 0 ; i < 10 ; ++i)
{
System.out.println("This is lost: I am " +
Thread.currentThread());
out.println("This is not lost: I am " +
Thread.currentThread());
Thread.sleep(1000);
}
}
catch(InterruptedException e) {}
}
}
public void testThreads() throws IOException,InterruptedException
{
PipedWriter writer = new PipedWriter();
BufferedReader reader = new BufferedReader(new PipedReader(writer));
PrintWriter threadOut = new PrintWriter(writer);
Worker a = new Worker(threadOut);
Worker b = new Worker(threadOut);
a.start();
b.start();
threadOut.println("Main thread is " + Thread.currentThread());
while(a.isAlive() || b.isAlive())
{
while(reader.ready())
{
System.out.println(reader.readLine());
}
}
}
}
robot.txt:
*Test Case*
| TC | Import Library | com.nsn.mylib.MyLib
| | Test Threads