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

Open
#75 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
desktop-dev

Research direction

Start by reproducing the Python 3.11 PyQt segfault with cothread.iqt(run_exec=True), then inspect input_hook.py around iqt(), QApplication.exec(), cothread.Spawn(), and the immediate cothread.Yield(). Compare the run_exec=False and removed-Yield workarounds; done means the documented execution and yield paths no longer segfault.

Written by the indexing model from the issue text.

Description

bug

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.

Dominant language
C
Stars
13
Forks
11
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DiamondLightSource/cothread

All issues in DiamondLightSource/cothread

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.