mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-07 06:54:01 +08:00
HACK: Call gc.collect in test_examples.
We need to call gc.collect before tearing down our class because we have a cycle between TradingAlgorithm and AlgorithmSimulator which ultimately holds a reference to the pipeline engine passed to the tests here. This means that we're not guaranteed to have deleted our disk-backed resource readers (e.g. SQLiteAdjustmentReader) before trying to delete the tempdir, which causes failures on Windows because Windows doesn't allow you to delete a file if someone still has an open handle to that file. The real fix for this is to break the cycle between TradingAlgorithm and AlgorithmSimulator, but that requires significant breaking API changes.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from functools import partial
|
||||
import gc
|
||||
import tarfile
|
||||
|
||||
import matplotlib
|
||||
@@ -53,6 +54,20 @@ class ExamplesTests(WithTmpDir, ZiplineTestCase):
|
||||
serialization='pickle',
|
||||
)
|
||||
|
||||
# We need to call gc.collect before tearing down our class because we
|
||||
# have a cycle between TradingAlgorithm and AlgorithmSimulator which
|
||||
# ultimately holds a reference to the pipeline engine passed to the
|
||||
# tests here.
|
||||
|
||||
# This means that we're not guaranteed to have deleted our disk-backed
|
||||
# resource readers (e.g. SQLiteAdjustmentReader) before trying to
|
||||
# delete the tempdir, which causes failures on Windows because Windows
|
||||
# doesn't allow you to delete a file if someone still has an open
|
||||
# handle to that file.
|
||||
|
||||
# :(
|
||||
cls.add_class_callback(gc.collect)
|
||||
|
||||
@parameterized.expand(examples.EXAMPLE_MODULES)
|
||||
def test_example(self, example_name):
|
||||
actual_perf = examples.run_example(
|
||||
|
||||
Reference in New Issue
Block a user