Closed blthayer closed 1 year ago
cc @phlptp
One of the things cleanup library is doing is essentially garbage collecting the threads that were started up. This can take some time and depends on the OS. Since the threads need to handle the shutdown of the sockets/files and make sure the connections are disconnected safely. In many cases sleeping in effect does the same thing. Many of the tests in C++ call the cleanup after each test to make sure there is no stray threads running around to impact the tests.
@phlptp: Thanks for the reply!
In https://github.com/GMLC-TDC/pyhelics/pull/26, the Python classes were updated so that upon garbage collection of an instance, helicsCleanupLibrary
is called. Does this seem appropriate to you?
@kdheepak: I'll be interested to know if this is a "non-issue" after the update in #26.
Closing out as HELICS v2 is deprecated (and this issue may have been specifically addressed in #26).
I don't 100% understand the cause of this issue, but I do have a solution. So, rather than trying to verbosely describe what's going on, I'm going to let the code do the talking.
Platform/Versions
OS
OS: Windows 10 Pro Version: 20H2 Build: 19042.1081 Experience: Windows Feature Experience Pack 120.2212.3530.0
Software
helics
on PyPI): v.2.7.1.post1Reproducing
After setting up a virtual environment (outside the scope of this ticket), put the following code in
test_bug.py
:Now, run the tests (in your activated virtual environment):
pytest test_bug.py
. Expected output:Notice that
test_create_combo_fed_with_broker
failed unexpectedly.Next, comment out the entirety of
test_cannot_create_combo_fed_without_broker
and execute the tests (well, just one test this time) again. Expected output:These two tests are completely isolated, yet
test_cannot_create_combo_fed_without_broker
is interfering withtest_create_combo_fed_with_broker
.Next, uncomment
test_cannot_create_combo_fed_without_broker
to restore the test module to its original state. Now, add the following fixture beforetest_cannot_create_combo_fed_without_broker
:The
autouse=True
flag means this fixture will be run before every test.Expected output after re-running the tests:
Note that I cannot provide any guarantee that
helicsCleanupLibrary
is actually solving the problem by whatever cleanup actions it is taking. If you add animport time
line to the top of the module and replaceh.helicsCleanupLibrary()
withtime.sleep(1)
the tests also pass.