Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
threading.pending
Gets the number of concurrent threads currently running in the strategy program.
pending()Examples
Create two concurrently running threads and call the pending() function at different time points.
javascript
function threadFun1() {
Log("threadFun1")
Sleep(3000)
}
function threadFun2() {
for (var i = 0; i < 3; i++) {
LogStatus(_D(), "print from threadFun2")
Sleep(3000)
}
}
function main() {
Log(`begin -- threading.pending():`, threading.pending())
var t1 = threading.Thread(threadFun1)
var t2 = threading.Thread(threadFun2)
Log(`after threading.Thread -- threading.pending():`, threading.pending())
t1.join()
t2.join()
Log(`after thread.join -- threading.pending():`, threading.pending())
}Returns
| Type | Description |
number | Number of concurrent threads currently running in the strategy program. |
See Also
Remarks
When the strategy's main() function starts running, directly calling pending() will return 1, because the main thread where main() function is located is also counted as a running thread.
Supports both backtesting system and live trading environment.