Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c35195

Browse files
authored
Update README.md
1 parent 0fd5b65 commit 6c35195

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ var result = np.cos(m);
5757
// get the floating point data of the result NDarray back to C#
5858
var data = result.GetData<double>(); // double[] { 0.54030231, -0.41614684, -0.9899925 , -0.65364362 }
5959
```
60+
## Multi-threading considerations
61+
Python/NumPy doesn't have real multi-threading support. There is no advantage to calling `numpy` functions from different threads because `pythonnet` requires you to use the Global Interpreter Lock (GIL) when doing so:
62+
63+
```csharp
64+
var a = np.arange(1000);
65+
var b = np.arange(1000);
66+
Task.Run(()=> {
67+
// when running on different threads you must lock!
68+
using (Py.GIL())
69+
{
70+
np.matmul(a, b);
71+
}
72+
});
73+
Task.Run(()=> {
74+
// when running on different threads at the same time you must lock or you will get an exception!
75+
using (Py.GIL())
76+
{
77+
np.matmul(a, b);
78+
}
79+
});
80+
```
6081

6182
## Numpy.NET vs NumSharp
6283

0 commit comments

Comments
 (0)