Skip to content

Commit 3389286

Browse files
committed
Update examples to acquire GIL state
1 parent 5c32993 commit 3389286

5 files changed

Lines changed: 25 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vs
2+
.venv
23
bin
34
obj
45
Packages

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ In addition to the Python Scripting package you need to have a version of [Pytho
1616
To create a virtual environment you can run the following command from inside the folder where you want to install the environment:
1717

1818
```ps
19-
python -m venv example-env
19+
python -m venv .venv
2020
```
2121

2222
## Create a Python runtime
@@ -55,7 +55,7 @@ To interface with Python state variables, you can use the [Get](xref:Bonsai.Scri
5555
:::
5656

5757
> [!Warning]
58-
> All the operators in the Python Scripting package run under the Python [Global Interpreter Lock](https://docs.python.org/3/glossary.html#term-global-interpreter-lock). This means that although execution of Python code can be triggered asynchronously anywhere in the workflow, there will be a bottleneck when accessing the interpreter. Because of this, we currently do not recommend running large number of parallel calls to Python.
58+
> All the operators in the Python Scripting package must run under the Python [Global Interpreter Lock](https://docs.python.org/3/glossary.html#term-global-interpreter-lock). This means that although execution of Python code can be triggered asynchronously anywhere in the workflow, there will be a bottleneck when accessing the interpreter. Because of this, we currently do not recommend running large number of parallel calls to Python.
5959
6060
## Scripting Extensions
6161

docs/workflows/create-runtime.bonsai

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<WorkflowBuilder Version="2.7.1"
2+
<WorkflowBuilder Version="2.8.1"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
55
xmlns="https://bonsai-rx.org/2018/workflow">
66
<Workflow>
77
<Nodes>
88
<Expression xsi:type="Combinator">
99
<Combinator xsi:type="py:CreateRuntime">
10-
<py:PythonHome>example-env</py:PythonHome>
10+
<py:PythonHome>.venv</py:PythonHome>
1111
</Combinator>
1212
</Expression>
1313
</Nodes>

docs/workflows/get-set.bonsai

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<WorkflowBuilder Version="2.7.1"
2+
<WorkflowBuilder Version="2.8.1"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
55
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
@@ -13,6 +13,9 @@
1313
<rx:Period>PT1S</rx:Period>
1414
</Combinator>
1515
</Expression>
16+
<Expression xsi:type="Combinator">
17+
<Combinator xsi:type="py:ObserveOnGIL" />
18+
</Expression>
1619
<Expression xsi:type="Combinator">
1720
<Combinator xsi:type="py:Set">
1821
<py:VariableName>time</py:VariableName>
@@ -24,6 +27,9 @@
2427
<wie:SuppressRepetitions>false</wie:SuppressRepetitions>
2528
</Combinator>
2629
</Expression>
30+
<Expression xsi:type="Combinator">
31+
<Combinator xsi:type="py:ObserveOnGIL" />
32+
</Expression>
2733
<Expression xsi:type="Combinator">
2834
<Combinator xsi:type="py:Get">
2935
<py:VariableName>time</py:VariableName>
@@ -32,7 +38,9 @@
3238
</Nodes>
3339
<Edges>
3440
<Edge From="0" To="1" Label="Source1" />
35-
<Edge From="2" To="3" Label="Source1" />
41+
<Edge From="1" To="2" Label="Source1" />
42+
<Edge From="3" To="4" Label="Source1" />
43+
<Edge From="4" To="5" Label="Source1" />
3644
</Edges>
3745
</Workflow>
3846
</WorkflowBuilder>

docs/workflows/share-module.bonsai

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<WorkflowBuilder Version="2.7.1"
2+
<WorkflowBuilder Version="2.8.1"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
55
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
@@ -20,6 +20,9 @@
2020
<rx:Period>PT0.01S</rx:Period>
2121
</Combinator>
2222
</Expression>
23+
<Expression xsi:type="Combinator">
24+
<Combinator xsi:type="py:ObserveOnGIL" />
25+
</Expression>
2326
<Expression xsi:type="SubscribeSubject">
2427
<Name>NewModule</Name>
2528
</Expression>
@@ -41,11 +44,12 @@
4144
</Nodes>
4245
<Edges>
4346
<Edge From="0" To="1" Label="Source1" />
44-
<Edge From="2" To="5" Label="Source1" />
45-
<Edge From="3" To="4" Label="Source1" />
46-
<Edge From="4" To="5" Label="Source2" />
47-
<Edge From="4" To="6" Label="Source2" />
48-
<Edge From="5" To="6" Label="Source1" />
47+
<Edge From="2" To="3" Label="Source1" />
48+
<Edge From="3" To="6" Label="Source1" />
49+
<Edge From="4" To="5" Label="Source1" />
50+
<Edge From="5" To="6" Label="Source2" />
51+
<Edge From="5" To="7" Label="Source2" />
52+
<Edge From="6" To="7" Label="Source1" />
4953
</Edges>
5054
</Workflow>
5155
</WorkflowBuilder>

0 commit comments

Comments
 (0)