You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-1
Original file line number
Diff line number
Diff line change
@@ -161,7 +161,8 @@ Note that `force_rebuild` does not work when importing the module concurrently.
161
161
162
162
### Can I import my model concurrently?
163
163
164
-
It's safe to use `cppimport` to import a module concurrently using multiple threads, processes or even machines!
164
+
It's (mostly) safe to use `cppimport` to import a module concurrently using multiple threads, processes or even machines!
165
+
There's an exception if your filesystem does not support file locking - see the next section.
165
166
166
167
Before building a module, `cppimport` obtains a lockfile preventing other processors from building it at the same time - this prevents clashes that can lead to failure.
167
168
Other processes will wait maximum 10 mins until the first process has built the module and load it. If your module does not build within 10 mins then it will timeout.
@@ -173,6 +174,44 @@ cppimport.settings['lock_timeout'] = 10*60 # 10 mins
173
174
174
175
You should not use `force_rebuild` when importing concurrently.
175
176
177
+
### Acquiring the lock hangs or times out unexpectedly - what's going on?
178
+
Certain platforms (e.g. those running
179
+
a Data Virtualization Service, DVS) do not support file locking. If you're on Linux with access to `flock`, you can test whether
180
+
locking is supported (credit to [this page](https://help.univention.com/t/howto-verify-the-mounted-filesystem-supports-file-locking/10149)):
181
+
182
+
```bash
183
+
touch testfile
184
+
flock ./testfile true&&echo ok ||echo nok
185
+
```
186
+
187
+
If locking is not supported, you can disable the file lock in
188
+
the cppimport global settings:
189
+
190
+
```python
191
+
cppimport.settings['use_filelock'] =False
192
+
```
193
+
194
+
This setting must be changed before you import any
195
+
code. By setting `use_filelock=False`, you become responsible
196
+
for ensuring that only a single process
197
+
(re)builds the package at a time. For example: if you're
198
+
using [mpi4py](https://mpi4py.readthedocs.io/en/stable/)
199
+
to run independent, communicating processes, here's how
200
+
to protect the build:
201
+
202
+
```python
203
+
from mpi4py import MPI
204
+
import cppimport, cppimport.import_hook
205
+
cppimport.settings["use_filelock"] = False
206
+
207
+
pid = MPI.COMM_WORLD.Get_rank()
208
+
209
+
if pid == 0:
210
+
import somecode # Process 0 compiles extension if needed
0 commit comments