question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PyDoc ValueError: signal only works in main thread

See original GitHub issue

Create file “test.py” with this content:

import pyxel
pyxel.init(160, 120)

Then run pydoc -b from the same directory.

Now navigate to your test module and get the error:

ErrorDuringImport: problem in test - ValueError: signal only works in main thread or with pypy.thread.enable_signals()

I’m new in python so sorry if my issue is noobish, but I have no idea how to provide documentation to my app due to this error.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bloodywingcommented, Nov 28, 2020

This would work:

import pyxel


class App:
    def __init__(self):
        pyxel.init(160, 120, caption="Hello Pyxel")
        pyxel.image(0).load(0, 0, "assets/pyxel_logo_38x16.png")
        pyxel.run(self.update, self.draw)

    def update(self):
        if pyxel.btnp(pyxel.KEY_Q):
            pyxel.quit()

    def draw(self):
        pyxel.cls(0)
        pyxel.text(55, 41, "Hello, Pyxel!", pyxel.frame_count % 16)
        pyxel.blt(61, 66, 0, 0, 0, 38, 16)

if __name__ == '__main__':
    App()

this prevents creating the object during import too. Usually people don’t import example scripts and simply run them. An exception is things like pydoc, which will scan every directory in a module. It also looks like this behavior changed over time in python:https://bugs.python.org/issue38904

1reaction
bloodywingcommented, Nov 27, 2020

put pyxel.init in a function or behind a if __name__ == '__main__' so it won’t call pyxel.init during importing a module

import pyxel


def main():
    pyxel.init(160, 120)
    # ... more pyxel calls here, pyxel.run(...) etc.


if __name__ == '__main__':
    main()
Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: signal only works in main thread - Stack Overflow
Python signal handlers are always executed in the main Python thread, even if the signal was received in another thread. This means that...
Read more >
signal only works in main thread of the main interpreter #1
I am getting this error "signal only works in main thread of the main interpreter". Can you please explain it to me, how...
Read more >
Issue 38904: "signal only works in main thread" in main thread
The problem for both modules is that the Python runtime may have actually been initialized in a different thread, which is the actual...
Read more >
ValueError('signal only works in main thread') - W&B Help
ValueError ('signal only works in main thread'). I'm running a hyper parameter sweep using PL and Weights and Biases's framework.
Read more >
ValueError: signal only works in main thread - DevPress - CSDN
Answer a question When i run this code i get this error: ValueError: signal only works in main thread I'm using ActiveMQ.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found