Skip to content

Get Dynamically Updating Values while Python Script is Running #2025

Answered by ncguilbeault
jaroducsb asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there,

Yes, this is possible. The key lies in performing the example() function asynchronously. The current behavior you're seeing is due to python's Global Interpreter Lock (GIL), which ensures that the Python code you are running executes synchronously in a single thread. To access your variables dynamically, you'll need to run your function asynchronously in a separate thread. Fortunately, there are several options for doing this in Python.

I'm attaching an example using the Bonsai.Scripting.Python package to demonstrate one approach that I've had success with. It uses the python packages asyncio and threading to run the example function asynchronously in a seperate thread. The exam…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jaroducsb
Comment options

Answer selected by jaroducsb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants