Skip to content

Commit fff7bfb

Browse files
committed
Describe PyCall.without_gvl in README
1 parent 95bf1bf commit fff7bfb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ the `Math.sin` in Ruby:
6161
Type conversions from Ruby to Python are automatically performed for numeric,
6262
boolean, string, arrays, and hashes.
6363

64+
### Releasing the RubyVM GVL during Python function calls
65+
66+
You may want to release the RubyVM GVL when you call a Python function that takes very long runtime.
67+
PyCall provides `PyCall.without_gvl` method for such purpose. When PyCall performs python function call,
68+
PyCall checks the current context, and then it releases the RubyVM GVL when the current context is in a `PyCall.without_gvl`'s block.
69+
70+
```ruby
71+
PyCall.without_gvl do
72+
# In this block, all Python function calls are performed without
73+
# the GVL acquisition.
74+
pyobj.long_running_function()
75+
end
76+
77+
# Outside of PyCall.without_gvl block,
78+
# all Python function calls are performed with the GVL acquisition.
79+
pyobj.long_running_function()
80+
```
81+
6482
### Debugging python finder
6583

6684
When you encounter `PyCall::PythonNotFound` error, you can investigate PyCall's python finder by setting `PYCALL_DEBUG_FIND_LIBPYTHON` environment variable to `1`. You can see the log like below:

0 commit comments

Comments
 (0)