robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
173 stars 14 forks source link

[Bug] Debugger doesnt return to command line when using RobotCode in combination with ScreenCapLibrary #131

Closed Daniwin82 closed 1 year ago

Daniwin82 commented 1 year ago

SUMMARY: When using the robotcode extension, RF doesn't return to the commandline after finishing a testcase. RF: 4.1.3 and 6.0.2 extension version: 0.28.2

SCENARIO: Install ScreenCapLibrary Add 'Start Video Recording' to the TestSetup Add 'Stop Video Recording' to the TestTearDown Run a simple testcase logging something

RESULT:

d-biehl commented 1 year ago

ok, I checked and found out that the ScreenCapLibrary is deleting the running ThreadPoolExecutor queues from the Python interpreter.

see here: https://github.com/rticau/ScreenCapLibrary/blob/146304edac5a062a39f6c738a0516212acbd0197/src/ScreenCapLibrary/client.py#L37 and here https://github.com/rticau/ScreenCapLibrary/blob/146304edac5a062a39f6c738a0516212acbd0197/src/ScreenCapLibrary/client.py#L252

This worked under Python 3.8, because the thread queues were still daemon threads. Daemon threads are simply killed by Python on shutdown.

In new Python version it is tried to shutdown these ThreadPoolExecutor threads reasonable, but because the list of ThreadPoolExecutor threads is empty now, because it is deleted by the ScreenCap library, there are still threads running in the background, which are not terminated correctly. That's why the debugger hangs, because it also runs ThreadPoolExecutor, but since Python doesn't know that it exists anymore, it won't be terminated.

From my point of view this must be corrected in the ScreenCapLibrary, because it not only affects the RobotCode debugger, but probably also other libraries, I know that the BrowserLibrary also uses ThreadpoolExecutors.

I would prefer not to implement a workaround only for a library that hacks the Python interpreter ;-)

I created an issue in the ScreenCapLibrary project, let's see what happens.

A workaround at the moment is to hack ScreenCapLibrary, just change this line: https://github.com/rticau/ScreenCapLibrary/blob/146304edac5a062a39f6c738a0516212acbd0197/src/ScreenCapLibrary/client.py#L252

like this:

    @staticmethod
    def clear_thread_queues():
        # _threads_queues.clear()
        pass
Daniwin82 commented 1 year ago

Hi Daniel,

Thanks for investigating the issue and for providing a workaround!

Daniel

d-biehl commented 1 year ago

@Daniwin82 Till now I have no answer from the screencaplibrary project, seems a little bit dead. What is your solution? did you make a fork of the project? Can I close this issue?

Daniwin82 commented 1 year ago

@d-biehl,

I applied the solution you provided locally. Works for me. I guess this issue can be closed.

Daniel

d-biehl commented 1 year ago

ok, thanks for feedback!

and maybe you can give this issue a thump up https://github.com/rticau/ScreenCapLibrary/issues/84