Skip to content

Functions (Threads)

CheshireCaat edited this page Mar 9, 2020 · 6 revisions

Running functions through threads is very similar to a regular launch through BasRemoteClient. The main feature of this type of launch is that you can control the launch yourself, stop the thread, and check whether it is busy with the execution of functions. This is very convenient cause it gives you complete control over the execution of functions.

If you want to create new thread then use client.create_thread() method. This method returns an instance of the BasThread class, that contains several useful methods and properties. Take a look at example.

thread = client.create_thread()

# Set up proxy.
await thread.run_function('SetProxy', {
    'Proxy': '127.0.0.1:11185',
    'IsSocks5': 'true',
})

# Check the ip of this proxy.
proxy_ip = await thread.run_function('CheckIp')

# Stop the thread.
await thread.stop()

Obviously, starting threads manually and calling functions through client is very similar. But in the case of a manual start, you can, for example, wait for the thread to finish working using is_running property.

# Run function only if thread is free.
if not thread.is_running:
    await thread.run_function('SomeFunction')

# Run another function only if thread is free.
if not thread.is_running:
    await thread.run_function('SomeAnotherFunction')
Clone this wiki locally