~mtrauts/universal-applets/universal-applets-extras

« back to all changes in this revision

Viewing changes to src/NetSpeed/NetSpeedScreenlet.py

  • Committer: Przemyslaw Firszt
  • Date: 2008-12-29 14:36:07 UTC
  • Revision ID: pefi@epf.pl-20081229143607-xb8mh5gg048q5qwl
Division by zero error fixed

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
                #calculate the transfer speed
114
114
                upload_delta = upload - self.upload  
115
115
                download_delta = download  - self.download
116
 
                time_delta = time_epoch - self.time_epoch               
117
 
                upload_speed = upload_delta / time_delta
118
 
                download_speed = download_delta / time_delta
119
 
                #store upload,download and time for next calculation cycle
120
 
                self.upload = upload
121
 
                self.download = download
122
 
                self.time_epoch = time_epoch
 
116
                time_delta = time_epoch - self.time_epoch
 
117
                try:
 
118
                        upload_speed = upload_delta / time_delta
 
119
                        download_speed = download_delta / time_delta
 
120
                        #store upload,download and time for next calculation cycle
 
121
                        self.upload = upload
 
122
                        self.download = download
 
123
                        self.time_epoch = time_epoch
 
124
                except ZeroDivisionError:
 
125
                        #Do nothing - cannot calculate speed with time_delta = 0
 
126
                        pass
 
127
 
 
128
 
123
129
                #store upload/download  - on_draw function reads it and displays
124
130
                upload_unit="B"
125
131
                if upload_speed < 1024: