You need to do some debugging. I know nothing about your IDE but it's probably capable of printing to a console or a log. Pepper your code with print/log statements so that you can see where it's hanging up.
Do you not see a report of any problems? You should have a way to trace crashes. Find out how to use it. The information it reports can be very cryptic but it may point to the command in your code that caused the crash.