Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.submit
Subscription
threading
threading.Thread
threading.getThread
threading.mainThread
threading.currentThread
threading.Lock
threading.Condition
threading.Event
threading.Dict
threading.Serve
threading.pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Gets the thread object of the main thread, which is the thread where the main() function in the strategy is located.

mainThread()

Examples

  • Get the Thread object of the main thread and output the threadId of the main thread.

    javascript
    function main() { Log("Main thread ID:", threading.mainThread().id()) }
  • The thread object of the main thread can also be obtained in concurrent threads.

    javascript
    function test() { Log("Main thread ID output in test function:", threading.mainThread().id()) } function main() { var t1 = threading.Thread(test) t1.join() }

Returns

TypeDescription

Thread object

Thread object of the main thread.

See Also

Remarks

Supported in backtesting system and live trading environment.