Skip to content

Commit

Permalink
Merge pull request #995 from QuantConnect/lean-threads-background
Browse files Browse the repository at this point in the history
Update all LEAN threads to be Background threads
  • Loading branch information
jaredbroad committed Jun 30, 2017
2 parents 678b05b + 48fb380 commit 118d9aa
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Brokerages/Fxcm/FxcmBrokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public override void Connect()
Log.Error(exception);
}
}
});
}) { IsBackground = true };
_orderEventThread.Start();
while (!_orderEventThread.IsAlive)
{
Expand Down Expand Up @@ -262,7 +262,7 @@ public override void Connect()
{
Log.Error(exception);
}
});
}) { IsBackground = true };
_connectionMonitorThread.Start();
while (!_connectionMonitorThread.IsAlive)
{
Expand Down
2 changes: 1 addition & 1 deletion Brokerages/Oanda/OandaRestApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public override void Connect()
{
Log.Error(exception);
}
});
}) { IsBackground = true };
_connectionMonitorThread.Start();
while (!_connectionMonitorThread.IsAlive)
{
Expand Down
4 changes: 2 additions & 2 deletions Common/RealTimeSynchronizedTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class RealTimeSynchronizedTimer
public RealTimeSynchronizedTimer()
{
_period = TimeSpan.FromSeconds(0);
_thread = new Thread(Scanner);
_thread = new Thread(Scanner) { IsBackground = true };
}

/// <summary>
Expand All @@ -53,7 +53,7 @@ public RealTimeSynchronizedTimer(TimeSpan period, Action<DateTime> callback)
_period = period;
_callback = callback;
_timer = new Stopwatch();
_thread = new Thread(Scanner);
_thread = new Thread(Scanner) { IsBackground = true };
_stopped = false;
_triggerTime = DateTime.UtcNow.RoundUp(period);
}
Expand Down
2 changes: 1 addition & 1 deletion Common/Util/ParallelRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void Start(CancellationToken token)
}, CancellationToken.None);

_processQueueThread = new Thread(() => ProcessHoldQueue(token));
_processQueueThread = new Thread(() => ProcessHoldQueue(token)) { IsBackground = true };
_processQueueThread.Start();
}

Expand Down
2 changes: 1 addition & 1 deletion Common/Util/ParallelRunnerWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Start(CancellationToken token)
lock (_sync)
{
if (_thread != null) return;
_thread = new Thread(() => ThreadEntry(token));
_thread = new Thread(() => ThreadEntry(token)) { IsBackground = true };
_thread.Start();
}
}
Expand Down
10 changes: 5 additions & 5 deletions Engine/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void Run(AlgorithmNodePacket job, string assemblyPath)

//Start monitoring the backtest active status:
var statusPing = new StateCheck.Ping(algorithmManager, _systemHandlers.Api, _algorithmHandlers.Results, _systemHandlers.Notify, job);
var statusPingThread = new Thread(statusPing.Run);
var statusPingThread = new Thread(statusPing.Run) { IsBackground = true };
statusPingThread.Start();

try
Expand All @@ -105,7 +105,7 @@ public void Run(AlgorithmNodePacket job, string assemblyPath)
//-> Set the result handler type for this algorithm job, and launch the associated result thread.
_algorithmHandlers.Results.Initialize(job, _systemHandlers.Notify, _systemHandlers.Api, _algorithmHandlers.DataFeed, _algorithmHandlers.Setup, _algorithmHandlers.Transactions);

threadResults = new Thread(_algorithmHandlers.Results.Run, 0) {Name = "Result Thread"};
threadResults = new Thread(_algorithmHandlers.Results.Run, 0) { IsBackground = true, Name = "Result Thread" };
threadResults.Start();

IBrokerage brokerage = null;
Expand Down Expand Up @@ -227,9 +227,9 @@ public void Run(AlgorithmNodePacket job, string assemblyPath)
_algorithmHandlers.Results.SendStatusUpdate(AlgorithmStatus.Running);

//Launch the data, transaction and realtime handlers into dedicated threads
threadFeed = new Thread(_algorithmHandlers.DataFeed.Run) {Name = "DataFeed Thread"};
threadTransactions = new Thread(_algorithmHandlers.Transactions.Run) {Name = "Transaction Thread"};
threadRealTime = new Thread(_algorithmHandlers.RealTime.Run) {Name = "RealTime Thread"};
threadFeed = new Thread(_algorithmHandlers.DataFeed.Run) { IsBackground = true, Name = "DataFeed Thread" };
threadTransactions = new Thread(_algorithmHandlers.Transactions.Run) { IsBackground = true, Name = "Transaction Thread" };
threadRealTime = new Thread(_algorithmHandlers.RealTime.Run) { IsBackground = true, Name = "RealTime Thread" };

//Launch the data feed, result sending, and transaction models/handlers in separate threads.
threadFeed.Start(); // Data feed pushing data packets into thread bridge;
Expand Down

0 comments on commit 118d9aa

Please sign in to comment.