Python Forum
[PyGame] Python pygame hangs up after 40 minutes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Python pygame hangs up after 40 minutes
#1
Hi everybody!

I am trying to develop an interface for FPV flying using game joysticks.

The python test program based on pygame module reads inputs from two joystick units (HOTAS X56) and displays the values in a window created by tkinter module. Everything works fine, except.. after about 40 minutes the program starts to hang up (the initial update rate of about 10 times a second suddenly drops to 2-5 seconds after 40 minutes, and after that it may update 20-30 times, each time taking longer and longer, and then ceases to respond. It affects not only python program, but the whole system, i.e. I have to disconnect power to reboot. The slow-down is not progressive, i.e. during the first 40 minutes it works flawlessly and time between updates does not change, but then suddenly increases drastically till crash.

I tried to eliminate tkinter updates, but it did not change anything...

Any thoughts of what maybe wrong?

The way the program works:

start=time.time()
while True:
a=pygame.event.get()
pygame.event.clear() # another option I tried...
Aileron=Stick_unit.get_axis(0)

#here about 12 axis and about 16 buttons are read in the same way.

# Aileron_var.set (Aileron) # was used to display in tkinter screen, but after commenting this out still crashed...

end=time.time()
print (end-start)

import pygame
import time
from tkinter import *
#  JOYSTICK BUTTON DEFINITION

Input_Test_Font="Courier 12 bold"
Input_Test_Back="green"
Input_Test_Width=16
Input_Test_Width2=6
Input_Test_Padx=5
Input_Test_Pady=5



global Aileron    # Aileron
global Elevator   # Elevator 
global Rudder     # Rudder
global Throttle   # Throttle
global Pan_Main   # Pan of the main camera
global Pan_HD     # Pan of the HD camera



global Pan_Temp   # Temporarily Pan main flight camera; once released, the settings set on Pan_Perm will take effect
global Tilt_Temp  # Temporarily Tilt main flight camera; once released, the settings set on Pan_Perm will take effect


global Camera2    # Video switch on airplane for momentarily switching video channel 2
global Camera3    # Video switch on airplane for momentarily switching video channel 3
global STAB_Temp  # Temporarily switch the STAB MODE on
global OSD_Up     # Pitlab Menu Navigation, Up
global OSD_Down   # Pitlab Menu Navigation, Down



def   Display_Controls():
    global Aileron,Elevator,Rudder,Aileron_var,Elevator_var,Rudder_var
    global Throttle, Pan_Main, Pan_HD,Throttle_var,Pan_Main_var,Pan_HD_var
    global Quick_Pan,Quick_Tilt,Quick_Pan_var,Quick_Tilt_var
    global Tilt_Main,Tilt_Main_var
    global Tilt_HD,Tilt_HD_var
    global Quick_Pan_2,Quick_Tilt_2,Quick_Pan_2_var,Quick_Tilt_2_var

    global VTX_Power_Up,VTX_Power_Down,VTX_Power_Up_var,VTX_Power_Down_var
    global VTX_2_Power_Up,VTX_2_Power_Down,VTX_2_Power_Up_var,VTX_2_Power_Down_var
    global High_Power,Low_Power,High_Power_var,Low_Power_var

    global Pitlab_Up,Pitlab_Down,OSD_Up,OSD_Down,OSD_Left,OSD_Right,Pitlab_Up_var,Pitlab_Down_var,OSD_Up_var,OSD_Down_var,OSD_Left_var,OSD_Right_var
    global AP_Manual,AP_Stab,AP_Auto,AP_Manual_var,AP_Stab_var,AP_Auto_var

    global Take_Control_var,Take_Control
    global Video_3_var,Video_3,Video_2_var,Video_2

    
    Aileron_var=StringVar()  
    Aileron_title=Label (Inp,text="Aileron:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Aileron_title.grid (column=0,row=0)
    Aileron_value=Label (Inp,textvariable=Aileron_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Aileron_value.grid  (column=1,row=0)
    Aileron_var.set (Aileron)
   
    Elevator_var=StringVar()
    Elevator_title=Label (Inp,text="Elevator:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Elevator_title.grid (column=0,row=1)
    Elevator_value=Label (Inp,textvariable=Elevator_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Elevator_value.grid  (column=1,row=1)
    Elevator_var.set (Elevator)
    
    Rudder_var=StringVar()
    Rudder_title=Label (Inp,text="Rudder:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Rudder_title.grid (column=0,row=2)
    Rudder_value=Label (Inp,textvariable=Rudder_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Rudder_value.grid  (column=1,row=2)
    Rudder_var.set (Rudder)

    Throttle_var=StringVar()
    Throttle_title=Label (Inp,text="Throttle:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Throttle_title.grid (column=0,row=3)
    Throttle_value=Label (Inp,textvariable=Throttle_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Throttle_value.grid  (column=1,row=3)
    Throttle_var.set (Throttle)

    Pan_Main_var=StringVar()
    Pan_Main_title=Label (Inp,text="Pan_Main:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pan_Main_title.grid (column=0,row=4)
    Pan_Main_value=Label (Inp,textvariable=Pan_Main_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pan_Main_value.grid  (column=1,row=4)
    Pan_Main_var.set (Pan_Main)

    Pan_HD_var=StringVar()
    Pan_HD_title=Label (Inp,text="Pan_HD:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pan_HD_title.grid (column=0,row=5)
    Pan_HD_value=Label (Inp,textvariable=Pan_HD_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pan_HD_value.grid  (column=1,row=5)
    Pan_HD_var.set (Pan_HD)

    Quick_Pan_var=StringVar()
    Quick_Pan_title=Label (Inp,text="Quick_Pan:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Pan_title.grid (column=0,row=6)
    Quick_Pan_value=Label (Inp,textvariable=Quick_Pan_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Pan_value.grid  (column=1,row=6)
    Quick_Pan_var.set (Quick_Pan)

    Quick_Tilt_var=StringVar()
    Quick_Tilt_title=Label (Inp,text="Quick_Tilt:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Tilt_title.grid (column=0,row=7)
    Quick_Tilt_value=Label (Inp,textvariable=Quick_Tilt_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Tilt_value.grid  (column=1,row=7)
    Quick_Tilt_var.set (Quick_Tilt)


    Tilt_Main_var=StringVar()
    Tilt_Main_title=Label (Inp,text="Tilt_Main:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Tilt_Main_title.grid (column=0,row=8)
    Tilt_Main_value=Label (Inp,textvariable=Tilt_Main_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Tilt_Main_value.grid  (column=1,row=8)
    Tilt_Main_var.set (Tilt_Main_var)

    Tilt_HD_var=StringVar()
    Tilt_HD_title=Label (Inp,text="Tilt_HD:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Tilt_HD_title.grid (column=0,row=9)
    Tilt_HD_value=Label (Inp,textvariable=Tilt_HD_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Tilt_HD_value.grid  (column=1,row=9)
    Tilt_HD_var.set (Tilt_HD_var)

    Quick_Pan_2_var=StringVar()
    Quick_Pan_2_title=Label (Inp,text="Quick_Pan_2:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Pan_2_title.grid (column=0,row=10)
    Quick_Pan_2_value=Label (Inp,textvariable=Quick_Pan_2_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Pan_2_value.grid  (column=1,row=10)
    Quick_Pan_2_var.set (Quick_Pan_2)

    Quick_Tilt_2_var=StringVar()
    Quick_Tilt_2_title=Label (Inp,text="Quick_Tilt_2:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Tilt_2_title.grid (column=0,row=11)
    Quick_Tilt_2_value=Label (Inp,textvariable=Quick_Tilt_2_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Quick_Tilt_2_value.grid  (column=1,row=11)
    Quick_Tilt_2_var.set (Quick_Tilt_2)



    VTX_Power_Up_var=StringVar()  
    VTX_Power_Up_title=Label (Inp,text="VTX Power Up:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_Power_Up_title.grid (column=4,row=0)
    VTX_Power_Up_value=Label (Inp,textvariable=VTX_Power_Up_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_Power_Up_value.grid  (column=5,row=0)
    VTX_Power_Up_var.set (VTX_Power_Up)
    
    VTX_Power_Down_var=StringVar()  
    VTX_Power_Down_title=Label (Inp,text="VTX Power Down:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_Power_Down_title.grid (column=4,row=1)
    VTX_Power_Down_value=Label (Inp,textvariable=VTX_Power_Down_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_Power_Down_value.grid  (column=5,row=1)
    VTX_Power_Down_var.set (VTX_Power_Down)
 
    VTX_2_Power_Up_var=StringVar()  
    VTX_2_Power_Up_title=Label (Inp,text="VTX 2 Power Up:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_2_Power_Up_title.grid (column=4,row=2)
    VTX_2_Power_Up_value=Label (Inp,textvariable=VTX_2_Power_Up_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_2_Power_Up_value.grid  (column=5,row=2)
    VTX_2_Power_Up_var.set (VTX_2_Power_Up)
    
    VTX_2_Power_Down_var=StringVar()  
    VTX_2_Power_Down_title=Label (Inp,text="VTX 2 Power Down:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_2_Power_Down_title.grid (column=4,row=3)
    VTX_2_Power_Down_value=Label (Inp,textvariable=VTX_2_Power_Down_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    VTX_2_Power_Down_value.grid  (column=5,row=3)
    VTX_2_Power_Down_var.set (VTX_2_Power_Down)

    High_Power_var=StringVar()  
    High_Power_title=Label (Inp,text="High Power:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    High_Power_title.grid (column=4,row=4)
    High_Power_value=Label (Inp,textvariable=High_Power_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    High_Power_value.grid  (column=5,row=4)
    High_Power_var.set (High_Power)

    Low_Power_var=StringVar()  
    Low_Power_title=Label (Inp,text="Low Power:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Low_Power_title.grid (column=4,row=5)
    Low_Power_value=Label (Inp,textvariable=Low_Power_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Low_Power_value.grid  (column=5,row=5)
    Low_Power_var.set (Low_Power)

    Pitlab_Up_var=StringVar()  
    Pitlab_Up_title=Label (Inp,text="Pitlab Up:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pitlab_Up_title.grid (column=4,row=6)
    Pitlab_Up_value=Label (Inp,textvariable=Pitlab_Up_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pitlab_Up_value.grid  (column=5,row=6)
    Pitlab_Up_var.set (Pitlab_Up)

    Pitlab_Down_var=StringVar()  
    Pitlab_Down_title=Label (Inp,text="Pitlab Down:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pitlab_Down_title.grid (column=4,row=7)
    Pitlab_Down_value=Label (Inp,textvariable=Pitlab_Down_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Pitlab_Down_value.grid  (column=5,row=7)
    Pitlab_Down_var.set (Pitlab_Down)

    OSD_Up_var=StringVar()  
    OSD_Up_title=Label (Inp,text="OSD Up:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Up_title.grid (column=4,row=8)
    OSD_Up_value=Label (Inp,textvariable=OSD_Up_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Up_value.grid  (column=5,row=8)
    OSD_Up_var.set (OSD_Up)

    OSD_Down_var=StringVar()  
    OSD_Down_title=Label (Inp,text="OSD Down:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Down_title.grid (column=4,row=9)
    OSD_Down_value=Label (Inp,textvariable=OSD_Down_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Down_value.grid  (column=5,row=9)
    OSD_Down_var.set (OSD_Down)

    OSD_Left_var=StringVar()  
    OSD_Left_title=Label (Inp,text="OSD Left:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Left_title.grid (column=4,row=10)
    OSD_Left_value=Label (Inp,textvariable=OSD_Left_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Left_value.grid  (column=5,row=10)
    OSD_Left_var.set (OSD_Left)

    OSD_Right_var=StringVar()  
    OSD_Right_title=Label (Inp,text="OSD Right:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Right_title.grid (column=4,row=11)
    OSD_Right_value=Label (Inp,textvariable=OSD_Right_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    OSD_Right_value.grid  (column=5,row=11)
    OSD_Right_var.set (OSD_Right)

    AP_Manual_var=StringVar()  
    AP_Manual_title=Label (Inp,text="AP Manual:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    AP_Manual_title.grid (column=4,row=12)
    AP_Manual_value=Label (Inp,textvariable=AP_Manual_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    AP_Manual_value.grid  (column=5,row=12)
    AP_Manual_var.set (AP_Manual)

    AP_Stab_var=StringVar()  
    AP_Stab_title=Label (Inp,text="AP Stab:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    AP_Stab_title.grid (column=4,row=13)
    AP_Stab_value=Label (Inp,textvariable=AP_Stab_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    AP_Stab_value.grid  (column=5,row=13)
    AP_Stab_var.set (AP_Stab)

    AP_Auto_var=StringVar()  
    AP_Auto_title=Label (Inp,text="AP Auto:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    AP_Auto_title.grid (column=4,row=14)
    AP_Auto_value=Label (Inp,textvariable=AP_Auto_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    AP_Auto_value.grid  (column=5,row=14)
    AP_Auto_var.set (AP_Auto)

    Take_Control_var=StringVar()  
    Take_Control_title=Label (Inp,text="Take Control:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Take_Control_title.grid (column=4,row=15)
    Take_Control_value=Label (Inp,textvariable=Take_Control_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Take_Control_value.grid  (column=5,row=15)
    Take_Control_var.set (Take_Control)

    Video_2_var=StringVar()  
    Video_2_title=Label (Inp,text="Video 2:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Video_2_title.grid (column=4,row=16)
    Video_2_value=Label (Inp,textvariable=Video_2_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Video_2_value.grid  (column=5,row=16)
    Video_2_var.set (Video_2)

    Video_3_var=StringVar()  
    Video_3_title=Label (Inp,text="Video 3:",relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Video_3_title.grid (column=4,row=17)
    Video_3_value=Label (Inp,textvariable=Video_3_var,relief=RAISED, font=Input_Test_Font,borderwidth=3,background=Input_Test_Back,foreground="white",width=Input_Test_Width2,padx=Input_Test_Padx,pady=Input_Test_Pady)
    Video_3_value.grid  (column=5,row=17)
    Video_3_var.set (Video_3)
    
    Inp.update()
    return;
# -----------------------------------

def Init_Joysticks():
    global Stick_Unit
    global Throttle_Unit
    global RJSTK
    global JSTK_error
    JSTK_error=0
    pygame.init()
    pygame.joystick.init()
    joystick_count=pygame.joystick.get_count()
    print ("Number of Joysticks connected: ",joystick_count)
    if joystick_count<2:
        print ("One or more joysticks was not initalized correctly or is not connected")
        JSTK_error=1
    if joystick_count>0:   
        joystick_0=pygame.joystick.Joystick(0)
        joystick_0.init()
        name=joystick_0.get_name()     
        if name=="Mad Catz Saitek Pro Flight X-56 Rhino Stick":
            Stick_Unit=joystick_0
        if name=="Mad Catz Saitek Pro Flight X-56 Rhino Throttle":
            Throttle_Unit=joystick_0
    if joystick_count>1:   
        joystick_1=pygame.joystick.Joystick(1)
        joystick_1.init()
        name=joystick_1.get_name()
        if name=="Mad Catz Saitek Pro Flight X-56 Rhino Stick":
            Stick_Unit=joystick_1
        if name=="Mad Catz Saitek Pro Flight X-56 Rhino Throttle":
            Throttle_Unit=joystick_1
            

    print ("Joystick Unit:",Stick_Unit.get_name())
    print ("Throttle Unit:",Throttle_Unit.get_name())
    print (Throttle_Unit.get_numbuttons())
    return;
# ---------------------------------------------
    
Inp=Tk()
Inp.geometry('880x800+100+100')
Inp.title("INPUT TEST SCREEN")
Inp.update()

Init_Joysticks()

Aileron=0
Elevator=0
Quick_Pan_2=0
Quick_Tilt_2=0
Rudder=0
Throttle=0
Pan_Main=0
Quick_Pan=0
Quick_Tilt=0
Pan_HD=0
Tilt_Main=0
Tilt_HD=0

VTX_Power_Up=0
VTX_Power_Down=0
VTX_2_Power_Up=0
VTX_2_Power_Down=0
High_Power=0
Low_Power=0
Pitlab_Up=0
Pitlab_Down=0
OSD_Up=0
OSD_Down=0
OSD_Left=0
OSD_Right=0
AP_Manual=0
AP_Stab=0
AP_Auto=0
Take_Control=0
Video_2=0
Video_3=0


#Display_Controls()

start =time.time()


while True:


        # pygame.event.pump()
        a=pygame.event.get()
        pygame.event.clear()
   
        Aileron=int (Stick_Unit.get_axis(0)*100)
        Elevator=int (Stick_Unit.get_axis(1)*100)
        Quick_Pan_2=int (Stick_Unit.get_axis(2)*100)
        Quick_Tilt_2=int (Stick_Unit.get_axis(3)*100)
        Rudder=int (Stick_Unit.get_axis(4)*100)
        Throttle=int (Throttle_Unit.get_axis(1)*100)
        Pan_Main=int (Throttle_Unit.get_axis(2)*100)
        Quick_Pan=int (Throttle_Unit.get_axis(3)*100)
        Quick_Tilt=int (Throttle_Unit.get_axis(4)*100)
        Pan_HD=int (Throttle_Unit.get_axis(5)*100)
        Tilt_HD=int (Throttle_Unit.get_axis(6)*100)
        Tilt_Main=int (Throttle_Unit.get_axis(7)*100)

        VTX_Power_Up=Throttle_Unit.get_button(17)
        VTX_Power_Down=Throttle_Unit.get_button(18)
        VTX_2_Power_Up=Throttle_Unit.get_button(15)
        VTX_2_Power_Down=Throttle_Unit.get_button(16)
        High_Power=Throttle_Unit.get_button(4)
        Low_Power=Throttle_Unit.get_button(3)
        Pitlab_Up=Throttle_Unit.get_button(20)
        Pitlab_Down=Throttle_Unit.get_button(22)
        OSD_Up=Throttle_Unit.get_button(24)
        OSD_Down=Throttle_Unit.get_button(26)
        OSD_Left=Throttle_Unit.get_button(23)
        OSD_Right=Throttle_Unit.get_button(25)

        AP_Manual=Throttle_Unit.get_button(33)
        AP_Stab=Throttle_Unit.get_button(34)
        AP_Auto=Throttle_Unit.get_button(35)

        Take_Control=Stick_Unit.get_button(0)  
        Video_2=Stick_Unit.get_button(4)  
        Video_3=Stick_Unit.get_button(5)  
        """ 
        Aileron_var.set (Aileron)
        Elevator_var.set (Elevator)
        Quick_Pan_2_var.set (Quick_Pan_2)    
        Quick_Tilt_2_var.set (Quick_Tilt_2)
        Rudder_var.set (Rudder)
        Throttle_var.set (Throttle)
        Pan_Main_var.set (Pan_Main)   
        Pan_HD_var.set (Pan_HD)
        Quick_Pan_var.set (Quick_Pan)    
        Quick_Tilt_var.set (Quick_Tilt)
        Tilt_Main_var.set (Tilt_Main)
        Tilt_HD_var.set (Tilt_HD)
    
        VTX_Power_Up_var.set (VTX_Power_Up)
        VTX_Power_Down_var.set (VTX_Power_Down)
        VTX_2_Power_Up_var.set (VTX_2_Power_Up)
        VTX_2_Power_Down_var.set (VTX_2_Power_Down)
        High_Power_var.set(High_Power)
        Low_Power_var.set(Low_Power)
        Pitlab_Up_var.set (Pitlab_Up)
        Pitlab_Down_var.set (Pitlab_Down)
        OSD_Up_var.set (OSD_Up)
        OSD_Down_var.set (OSD_Down)
        OSD_Left_var.set (OSD_Left)
        OSD_Right_var.set (OSD_Right)
        AP_Manual_var.set (AP_Manual)
        AP_Stab_var.set (AP_Stab)
        AP_Auto_var.set (AP_Auto)
        Take_Control_var.set (Take_Control)
        Video_2_var.set (Video_2)
        Video_3_var.set (Video_3)
            
        Inp.update_idletasks()
        """      
        end=time.time()
        print (end-start,"   ", Aileron)
Reply
#2
Mixing tkinter and pygame can cause issues alone depending on the situation.

Your program is not runnable for us to test it
Error:
Traceback (most recent call last): File "test11.py", line 314, in <module> Init_Joysticks() File "test11.py", line 303, in Init_Joysticks print ("Joystick Unit:",Stick_Unit.get_name()) NameError: name 'Stick_Unit' is not defined
Recommended Tutorials:
Reply
#3
The problem is that it runs perfectly... until it starts hanging

To test it you have to have the joysticks connected.

I will try and eliminate completely tkinter references and module to try and isolate the problem, but my suspicion is that somehow this had to do with pygame module and maybe incorrect event processing
Reply
#4
ive never used joysticks in pygame. So i cant really help with that as i am unfamiliar with it. You can try reddit.
Recommended Tutorials:
Reply
#5
Ok. I will try it
Reply
#6
This could all be done in pygame. If you really need to use joystick.

First. You need to redo code with some structure. List, Dicts, Functions, and Classes. Need to reduce or eliminate globals.

Second tkinter has a main loop. Creating a second loop probably where your problems is.

If you still want to use pygame in tkinter. Don't use pygame.init. Only initialize what you need.
To get pygame event loop in tkinter. You going to have to use tkinter after method.
99 percent of computer problems exists between chair and keyboard.
Reply
#7
I just started with the project and I am trying basic functionalities...
The program will run on raspberry Pi

The complete program would have to do the following:
Read inputs from joysticks using pygame (here I am stuck, because only pygame can read USB joysticks)
Read inputs (a formatted ASCII sequence) from arduino 2560 through I2C
On basis of the inputs, an output ASCII sentence will be prepared and sent through modem
From the same modem, an input ASCII stream would be read.
In addition, there would be 6-7 output screens which I wanted to do in tkinter (due to the tables) which would display different info in tabulated form.
Reply
#8
I eliminated completely the tkinter module, still got the same hang-up after 45 minutes...
Reply
#9
1. Show code.

Forget trying to use pygame in tkinter. So far to many hurdles to jump.
Either use pygame or tkinter.
Joystick module you could use for tkinter.
https://pypi.org/project/joystick/
99 percent of computer problems exists between chair and keyboard.
Reply
#10
It would help if you made a runnable example for us for a general joystick that reproduces the problem. Something we can easily input our own joystick with. Currently i get an invalid axis with my joystick so i cant reproduce the problem.
Error:
Logitech Logitech Attack 3 Traceback (most recent call last): File "test11.py", line 378, in <module> Quick_Tilt_2=int (Stick_Unit.get_axis(3)*100) pygame.error: Invalid joystick axis
I would also make a separate program that does not use a joystick at all to try to reproduce the problem. Then we dont need a joystick at all. Especially if its event related.

It would also be super helpful to see your full code without the tkinter module that creates the lag after ~40 minutes.

My suggestion would be to keep narrowing it down until the problem is gone thus pinpointing the problem. That is all we are going to do when we get a runnable example from you. Unless we see a bottleneck in your current code.
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pygame in 90 Minutes - For Beginners syntax issues GoldenHarvey 6 2,535 Dec-18-2023, 10:11 AM
Last Post: KeeleyGreenfelder

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020