Fixed sporadic problems with timeouts on Win Py2.6.
Fixed sporadic problems with timeouts on Win Py2.6.

Timeout tests started to fail sporadically on Windows with Python 2.6
after recent refactoring of keyword execution logic. Based on git
bisect the "bad commit" was 08390eb2b544dc4d9ef7dc00fc977d85e6b302a9.

The actual problem turned out to be in the code related to
asynchronously raising exception in the runner thread to signal
timeout. In some cases the exception was raised so that it occurred
during the code that was trying to cancel it. Most likely the old
keyword execution code catched the resulting TimeoutError but that
didn't anymore happen after the refactoring. Not sure why that problem
only manifested itself with Python 2.6, though.

The fix has two parts:
- Check has timeout occurred inside try/finally and wait for it to be
  actually raised. This ensures it won't happen inside the finally block.
- Add new `_finished` flag to signal execution has finished and timeout
  should not be raised. Also use locks to avoid race conditions when
  setting `_finished` and `_timeout_occurred`.

Interestingly the problem seems to vanish with just the first
fix. Looking at the code, the problem could occur also then, so it is safer
to keep both parts.

snyderr/robotframework,alexandrul-ci/robotframework,alexandrul-ci/robotframework,HelioGuilherme66/robotframework,snyderr/robotframework,jaloren/robotframework,alexandrul-ci/robotframework,HelioGuilherme66/robotframework,snyderr/robotframework,jaloren/robotframework,robotframework/robotframework,jaloren/robotframework,joongh/robotframework,robotframework/robotframework,robotframework/robotframework,HelioGuilherme66/robotframework,joongh/robotframework,alexandrul-ci/robotframework,snyderr/robotframework,joongh/robotframework,snyderr/robotframework,joongh/robotframework,alexandrul-ci/robotframework,joongh/robotframework,jaloren/robotframework,jaloren/robotframework