DiamondLightSource / DiamondLightSource/cothread

Using latest cothread on python3.11 with pyqt results in segfault

Open
#75 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
13
Forks
11
PR merge metrics
No merged PRs in 30d

Description

Calling this: cothread.iqt(run_exec=True)

Results in a segfault.

UPDATE 2

> Im seeing some issues with following the advice in update 1, things not working the way they used too.

UPDATE 1

> For the first fix below, QApplication.exec() should be spawned as a cothread, not called directly. Such as:
> cothread.Spawn(_qapp.exec)
>
> This works fine, but if you do any future yields or call any cothread functions which yield from the main thread it will segfault.
>
> So this works:
>
> ```
> def ticker():
> while True:
> cothread.Sleep(1)
> print("*** --------------------------------------------- tick")
>
> cothread.Spawn(_qapp.exec)
> cothread.Spawn(ticker)
> cothread.WaitForQuit()
> ```
> But this segfaults:
> ```
> cothread.Spawn(_qapp.exec)
> cothread.Yield()
> cothread.WaitForQuit()
> ```
> This is okayish as you typically spawning the exec thread is the last thing you do before running cothread.WaitForQuit().
> But obviously the root issue needs to be fixed.
>
> The second fix below suffers from the same issue.

Quick fixes:

- A quick fix can be made by either setting run_exec=False and calling QApplication.exec() manually.

- Or by removing the `cothread.Yield()` called immediately after` cothread.Spawn(getattr(_qapp, exec_name), stack_size = QT_STACK_SIZE)` in the iqt() function in input_hook.py

I don't yet understand the root cause of this issue, but will continue investigating.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.