Skip to content

Commit ac24a78

Browse files
CzakipsobolewskiPhDmelissawm
authored
Docs for 5195 from main repository (#7)
Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com> Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
1 parent 48443c7 commit ac24a78

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

docs/plugins/debug_plugins.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ When developing plugins in napari, you may encounter mistakes or bugs in your co
88
4. Reloading code during plugin development.
99
5. Isolating issues from napari.
1010
6. Logging and debug messages.
11+
7. Debugging segfaults/memory violation errors
1112

1213
## Debugging plugin start-up issues
1314

@@ -287,4 +288,24 @@ DEBUG: 20/09/2022 05:59:23 PM The input string was (logging): fast
287288
'You entered fast!'
288289
```
289290

290-
The full code changes and new files after applying the changes to the plugin in each step of the examples are [here](https://github.com/seankmartin/napari-plugin-debug/tree/full_code/napari-simple-reload).
291+
292+
The full code changes and new files after applying the changes to the plugin in each step of the examples are [here](https://github.com/seankmartin/napari-plugin-debug/tree/full_code/napari-simple-reload).
293+
294+
## Debugging segfaults/memory violation errors
295+
296+
If napari crashes with a segfault or memory violation error when using your plugin
297+
it may be connected with setting some viewer/layers properties outside main thread.
298+
Because of the limitations of the Qt library, such interactions with napari may lead to a crash.
299+
300+
To test if this is the case, you can use the `NAPARI_ENSURE_PLUGIN_MAIN_THREAD` environment variable to help debug the issue.
301+
302+
Set the environement variable: `NAPARI_ENSURE_PLUGIN_MAIN_THREAD=1`, then start napari and run your plugin.
303+
304+
```bash
305+
NAPARI_ENSURE_PLUGIN_MAIN_THREAD=1 napari
306+
```
307+
308+
Next, start using your plugin and observe if
309+
`RuntimeError("Setting attributes on a napari object is only allowed from the main Qt thread.")`
310+
occurred. If so, then you need to make sure that all of your plugin code that interacts with napari structures is executed
311+
in the main thread. For more details you could read the [multithreading](https://napari.org/stable/guides/threading.html) section of the documentation.

docs/plugins/test_deploy.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@ We recommend using
1212
[pytest](https://docs.pytest.org/en/6.2.x/getting-started.html) for testing your
1313
plugin. Aim for [100% test coverage](./best_practices.md#how-to-check-test-coverage)!
1414

15-
### The `make_napari_viewer` fixture
15+
### The `make_napari_viewer_proxy` fixture
1616

1717
Testing a napari `Viewer` requires some setup and teardown each time. We have
1818
created a [pytest fixture](https://docs.pytest.org/en/6.2.x/fixture.html) called
19-
`make_napari_viewer` that you can use (this requires that you have napari
19+
`make_napari_viewer_proxy` that you can use (this requires that you have napari
2020
installed in your environment).
2121

2222
To use a fixture in pytest, you simply include the name of the fixture in the
2323
test parameters (oddly enough, you don't need to import it!). For example, to
2424
create a napari viewer for testing:
2525

2626
```
27-
def test_something_with_a_viewer(make_napari_viewer):
28-
viewer = make_napari_viewer()
27+
def test_something_with_a_viewer(make_napari_viewer_proxy):
28+
viewer = make_napari_viewer_proxy()
2929
... # carry on with your test
3030
```
3131

32+
If you embed the viewer in your own application and need to access private attributes,
33+
you can use the `make_napari_viewer` fixture.
34+
3235
### Prefer smaller unit tests when possible
3336

3437
The most common issue people run into when designing tests for napari plugins is

0 commit comments

Comments
 (0)