Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all pi3d operations must be on the main Python thread. #13

Closed
rec opened this issue Oct 27, 2012 · 5 comments
Closed

all pi3d operations must be on the main Python thread. #13

rec opened this issue Oct 27, 2012 · 5 comments
Assignees
Labels
Milestone

Comments

@rec
Copy link
Collaborator

rec commented Oct 27, 2012

This took me a long time to boil down into a tiny test case. I still don't have a good fix for it in general though I can work around it in my codebase.

Take a look at this piece of test code. There's a tiny event_loop in a function called "event_loop" which simply displays a header image and nothing else.

You can see from the code that if you set ENABLE_BUG to False, event_loop runs in the main thread - if it's True, then the event loop runs in a new Python thread.

If you run the code with ENABLE_BUG=False, then you see the correct pink window with a header. If you run the code with ENABLE_BUG=True, you see a white screen with nothing in it.

(Note that if you set ENABLE_BUG to True, the program won't terminate with a control-C - you have to kill it from a separate terminal instance. This is expected behavior for Python threads - I could have put code to avoid that happening but didn't want to obscure the issue.)

@rec
Copy link
Collaborator Author

rec commented Oct 31, 2012

I just updated the bug title.

It turns out that any operation - even loading textures - has to run on the main Python thread.

This is really draggy if you're dynamically loading textures, because that loading has to run on the main thread - putting file IO on your display thread doesn't sound like a good idea, does it?

But at least it's a simpler-to-understand bug.

@alextz
Copy link

alextz commented Dec 17, 2012

rec, you just saved me a lot of time. I'd have found this bug the hard way.

Oddly enough, within the last week, I've found the same problem with a frame grabber on an Ubuntu PC. My not-yet-implemented solution is to put the frame grabber's logic in a subprocess and push the frames through a queue. I did some prelim testing and think the queue will not be a serious CPU hog.

Same thing might work in your (and my) case. The big time hog in loading textures is the image load, resizing and conversion. Once the thing is in a string, it can be pushed down a queue pretty fast, probably.

@rec
Copy link
Collaborator Author

rec commented Dec 17, 2012

Very glad to have helped.

It turns out that most of the computations associated with loading textures can be done on any thread - there are only some small key operations that must be done on the display thread.

Our alternate development branch has such a fix mostly implemented, but it will be some time before this is all ready to go...

@ghost ghost assigned rec Dec 19, 2012
@rec
Copy link
Collaborator Author

rec commented Dec 19, 2012

This needs to be fixed in THREE ways - we need to complete the changes involving the split of loading, we need to check to see that you're in the correct thread and report an error if you don't, and we need to document this better...

@rec
Copy link
Collaborator Author

rec commented Apr 1, 2013

I think this is basically done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants