简体   繁体   中英

Python Threading--Crash when updating the GUI

So here is my problem--

I am creating a python GUI application using wx python. Once the process button is clicked, there is some file creation/encoding that goes on behind the scenes. Initially, this froze EVERYTHING on the GUI while it was working, so I decided to do the file creation/encoding on a separate thread--Here is the rub, as soon as the method that created the thread finishes--(Relatively quickly) Here is the code that actually creates the threads:

for audiobook in AudioBookObjects:
        thread.start_new(self.createSingleBook, tuple([audiobook]))

So here is the weird part--on one machine that I used this code let one thread go, finish and come back without freezing the gui. On another machine, it shoots off two threads really quickly and they crash when they terminate! Does something change the behavior of threads between Operating systems? I am using the same version of python. I am ABSOLUTELY sure of that.

Basically, I need to know two things: What happen to python threads after the method that created them ends, and how can I build a GUI that does not freeze if the trigger method HAS to stick around for the threads to end gracefully!?

Thanks in advance! Let me know if you need anymore information

If i remeber correctly, windows does "real" threads, where in Linux threads are processes. The difference is, that normal threads share the same memory and processes do not.

I would guess your program crashes under win and runs under linux. If i'm not mistaken it's likely that your createSingleBook-threads accesses the same object, which doesn't seem to have a lock-protection.

With a real fork, everything is duplicated if not explicitly stated otherwise. So you would have some more protection against lock and race conditions.

Just my preliminary guess, anyone with greater insight feel free to correct me. Otherwise i would recommend to implement a lock on the object you are trying to manipulate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM