Skip to content

Instantly share code, notes, and snippets.

@avleen
Created August 3, 2011 00:54
Show Gist options
  • Save avleen/1121648 to your computer and use it in GitHub Desktop.
Save avleen/1121648 to your computer and use it in GitHub Desktop.
Line # Hits Time Per Hit % Time Line Contents
==============================================================
122 @profile
123 def send_partial(self, bytes):
124 3071513 6395122 2.1 1.5 if self.connection.closed:
125 return 0
126 3071513 5192907 1.7 1.2 if self.partial_message is None:
127 4344 4522134 1041.0 1.1 s = self.upload.get_upload_chunk()
128 4344 10362 2.4 0.0 if s is None:
129 69 92 1.3 0.0 return 0
130 4275 6385 1.5 0.0 index, begin, piece = s
131 4275 6661 1.6 0.0 self.partial_message = ''.join((
132 4275 29037 6.8 0.0 tobinary(len(piece) + 9), PIECE,
133 4275 2682681 627.5 0.6 tobinary(index), tobinary(begin), piece.tostring() ))
134 4275 12451 2.9 0.0 if DEBUG:
135 print 'sending chunk: '+str(index)+': '+str(begin)+'-'+str(begin+len(piece))
136
137 3071444 5832695 1.9 1.4 if bytes < len(self.partial_message):
138 3067173 130320284 42.5 31.2 self.connection.send_message_raw(self.partial_message[:bytes])
139 3067173 256394782 83.6 61.4 self.partial_message = self.partial_message[bytes:]
140 3067173 5914925 1.9 1.4 return bytes
141
142 4271 7758 1.8 0.0 q = [self.partial_message]
143 4271 6474 1.5 0.0 self.partial_message = None
144 4271 6703 1.6 0.0 if self.send_choke_queued:
145 self.send_choke_queued = False
146 self.outqueue.append(tobinary(1)+CHOKE)
147 self.upload.choke_sent()
148 self.just_unchoked = 0
149 4271 9497 2.2 0.0 q.extend(self.outqueue)
150 4271 7234 1.7 0.0 self.outqueue = []
151 4271 9219 2.2 0.0 q = ''.join(q)
152 4271 137333 32.2 0.0 self.connection.send_message_raw(q)
153 4271 8684 2.0 0.0 return len(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment