Skip to content

Commit 0f114df

Browse files
committed
Mute Python Library Logging
Redirects Python standard output (`sys.stdout`) to `devull`
1 parent 7902d62 commit 0f114df

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using System;
3434
using System.Collections.Concurrent;
3535
using System.Collections.Generic;
36+
using QuantConnect.Configuration;
3637

3738
namespace QuantConnect.AlgorithmFactory.Python.Wrappers
3839
{
@@ -99,6 +100,11 @@ public AlgorithmPythonWrapper(string moduleName)
99100
{
100101
throw new Exception("Please ensure that one class inherits from QCAlgorithm.");
101102
}
103+
104+
if (Config.GetBool("mute-python-library-logging", true))
105+
{
106+
PythonEngine.Exec("import os, sys; sys.stdout = open(os.devnull, 'w')");
107+
}
102108
}
103109
}
104110
catch (Exception e)

0 commit comments

Comments
 (0)