Skip to content
CheshireCaat edited this page Mar 9, 2020 · 10 revisions

Run functions with client

If you want to run the function, and you do not need to control the lifetime of the threads, use BasRemoteClient instance for this. In this case, the client itself creates and terminates BAS threads to perform functions.

The run_function() method returns an instance of the BasFunction class. Using it, you can stop the execution of a running function, get the ID of the thread in which it was run, or get the function result using method call function object with await keyword.

BasFunction object is awaitable. If you will use code like await function it will wait for the function to complete and return its result. If you do this again and the function is already completed, the same result will be returned.

Take a look at the examples:

Single function call

client = BasRemoteClient(options=Options(script_name='TestRemoteControl'))

await client.start()

# Call one function and get the result.
result = await client.run_function('GoogleSearch', {'Query': 'cats'})

# Output result to console.
print(result)

await client.close()
Clone this wiki locally