473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Any idea why execfile() call in Tkinter button cause "python.exe has stopped working"

17
Dear Experts:

I made one GUI interface with Tkinter. I have some buttons on the GUI and one button is designed as "start test" which will invoke one "start test" window. I put one "ok" and one "cancel" button in this window. When I click the "ok" button it will use execfile() to call another python file which will start multiple threads to run. The multiple threads did finish but I immediately got "python.exe has stopped working" error message. Do you have any suggestions? My operation system is Windows Vista with service pack 1. Looks like it is not related to OS and it could be related to my script. I attached part of my script below.

Thank you very much!

Haiyan

Related scripts in GUI side:
Expand|Select|Wrap|Line Numbers
  1.    def pressed_start_test(self):
  2.       self.Start_Test_Window = Toplevel()
  3.       self.Start_Test_Window.title("Start Test for Selected Slots")
  4.  
  5.       self.startTest_Label1 = Label( self.Start_Test_Window, text = "Start Test for Selected Slots?", width = 40, padx=5, pady=5, relief = RAISED )
  6.       self.startTest_Label1.grid( row = 0, column = 0, columnspan = 2, sticky = W+E+N+S )
  7.  
  8.       self.startTest_button1 = Button( self.Start_Test_Window, text = "OK", width = 20,
  9.                            padx=5, pady=5,
  10.                            command = self.pressed_startTest_OK,
  11.                            font = "Arial 9 bold")
  12.       self.startTest_button1.grid( row = 1, column = 0, columnspan = 1, sticky = W+E+N+S )
  13.       self.startTest_button1.bind( "<Enter>", self.rolloverEnter )
  14.       self.startTest_button1.bind( "<Leave>", self.rolloverLeave )
  15.  
  16.       self.startTest_button2 = Button( self.Start_Test_Window, text = "Cancel", width = 20,
  17.                            padx=5, pady=5,
  18.                            command = self.pressed_startTest_Cancel,
  19.                            font = "Arial 9 bold")
  20.       self.startTest_button2.grid( row = 1, column = 1, columnspan = 1, sticky = W+E+N+S )
  21.       self.startTest_button2.bind( "<Enter>", self.rolloverEnter )
  22.       self.startTest_button2.bind( "<Leave>", self.rolloverLeave )
  23.  
  24.    def pressed_startTest_OK(self):
  25.       valid_checked_button_list = self.get_checked_button_name()
  26.  
  27.       f = open('selected_slot_driveSN.list', 'w')
  28.       p = pickle.Pickler(f)
  29.       p.dump(valid_checked_button_list)
  30.       f.close()
  31.  
  32.       self.Start_Test_Window.destroy()
  33.       execfile("BootScript.py", globals())
  34.  
  35.  
  36.    def pressed_startTest_Cancel(self):
  37.       self.Start_Test_Window.destroy()
  38.  

Related scripts in BootScript.py:

Expand|Select|Wrap|Line Numbers
  1. for i in range(len(selected_slot__list)):
  2.    boat_slot_thread = IOProcessThread(selected_slot__list[i][1],       
  3.                                      selected_slot__list[i][0][1]-1)   # Slot Number
  4.    boat_slot_thread.start()
  5.    time.sleep(1)
  6.    print >> PC_process_log, "Boat_%d_Slot_%d_%s started..." %(selected_slot__list[i][0][0],
  7.                                                               selected_slot__list[i][0][1],
  8.                                                               selected_slot__list[i][1])
  9.  
The thread class definition:

Expand|Select|Wrap|Line Numbers
  1. class IOProcessThread(threading.Thread):
  2.  
  3.    #-------------------------------------------------------------------------------------------------------
  4.    # Override Thread's __init__ method to accept the parameters needed:
  5.    def __init__ ( self, SN, slot ):
  6.       threading.Thread.__init__ ( self )
  7.       self.SN = SN
  8.       self.slot = slot
  9.  
  10.    #-------------------------------------------------------------------------------------------------------
  11.    def run ( self ):
  12.       testStartTimeList = str(datetime.now())[0:19].split()
  13.       filenametuple = (self.SN, testStartTimeList[0], testStartTimeList[1].replace(':', '.'))# File name can't have ':', so replace with '.'
  14.       filename_log = '_'.join(filenametuple) + '.txt'    # Souce test out file
  15.       filename_csv = '_'.join(filenametuple) + '.csv'    # Date only test out file for database
  16.       testout_log = open(filename_log, 'w')
  17.       testout_csv = open(filename_csv, 'w')
  18.       stateMachine('INIT', self.slot, testout_log, testout_csv)
  19.  
Jul 30 '10 #1

✓ answered by bvdet

I am guessing here - Try hiding the window with withdraw() until execfile() is finished. You could also try exiting the main loop with quit().

3 2975
bvdet
2,851 Expert Mod 2GB
I am guessing here - Try hiding the window with withdraw() until execfile() is finished. You could also try exiting the main loop with quit().
Jul 30 '10 #2
Haiyan
17
@bvdet
Hi, bvdet:

Thanks a lot for your suggestions!

I did try following 4 options and they didn't work:

1:
self.Start_Test_Window.withdraw()
execfile("BootScript.py", globals())

2:
execfile("BootScript.py", globals())
self.Start_Test_Window.withdraw()

3:
execfile("BootScript.py", globals())
self.Start_Test_Window.destroy()

4:
self.Start_Test_Window.destroy()
execfile("BootScript.py", globals())

But the main GUI quit before the execfile() call will make it better and Python won't crash. You know I hope to keep the main Tkinter GUI alive to show the test status.

boat1.quit() # quit the GUI main loop
execfile("BootScript.py", globals())

Looks like it is not related to the multiple threads in the execfile("BootScript.py", globals()) call. I changed from "BootScript.py" to another simple python script with 20 threads running to print out something, and it works fine.

Then I tear the "BootScript.py" to small parts to debug which part caused the Python crash. It turns out one DLL I used ctypes to import, and python crashes after running the destructor of this DLL. I have to use this DLL file and I didn't find a way to handle this situation yet. I will post my finding with this thread if I can figure out this problem.

I tried to use C# to generate one quick GUI and it works fine for the "BootScript.py" call with multiple threads run.

Thanks a lot for your help!

Haiyan
Jul 31 '10 #3
Haiyan
17
Now I moved the destructor running out of main GUI and only run after main GUI terminated. The Python didn't get crashed any more.
Jul 31 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the...
2
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make....
6
by: Elaine Jackson | last post by:
I've got a script where a button gets pushed over and over: to cut down on the carpal tunnel syndrome I'd like to have the button respond to presses of the Enter key as well as mouse clicks; can...
1
by: Elaine Jackson | last post by:
In the script I'm writing, there's a Tkinter Button that contains a square image at some times and is blank at other times. Is there a smart way to make its dimensions stay the same throughout all...
1
by: Ajay | last post by:
hi! if i set two buttons to call the same function when they are pressed, is there any way, within the function of knowing which button invoked it. cheers -- Ajay Brar, CS Honours 2004
0
by: Casey Hawthorne | last post by:
Is there a better way to delete the image from a Tkinter button other than the following: - reconstructing the button - image=blank.gif -- Regards,
3
by: Shankar Iyer (siyer | last post by:
Hi, I have another Tkinter-related question. At the beginning of my program, a tkinter window is created with six buttons. Each of these buttons is assigned a function that should be executed...
3
by: shane12345 | last post by:
'''on execution of button.py a button appears ,after clicking on the button it calls bounce.py but after closing bounce.py the button also closes...but i want the button to remain open...please...
2
by: Fuzz13 | last post by:
Within a method I want based on an if then statement to trigger a button click but I don't know how. Is there a way to call a button click event?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.