MCPcopy Index your code
hub / github.com/pyload/pyload / tryReconnect

Method tryReconnect

module/ThreadManager.py:160–210  ·  view source on GitHub ↗

checks if reconnect needed

(self)

Source from the content-addressed store, hash-verified

158
159 #----------------------------------------------------------------------
160 def tryReconnect(self):
161 """checks if reconnect needed"""
162
163 if not (self.core.config["reconnect"]["activated"] and self.core.api.isTimeReconnect()):
164 return False
165
166 active = [x.active.plugin.wantReconnect and x.active.plugin.waiting for x in self.threads if x.active]
167
168 if not (0 < active.count(True) == len(active)):
169 return False
170
171 if not exists(self.core.config['reconnect']['method']):
172 if exists(join(pypath, self.core.config['reconnect']['method'])):
173 self.core.config['reconnect']['method'] = join(pypath, self.core.config['reconnect']['method'])
174 else:
175 self.core.config["reconnect"]["activated"] = False
176 self.log.warning(_("Reconnect script not found!"))
177 return
178
179 self.reconnecting.set()
180
181 #Do reconnect
182 self.log.info(_("Starting reconnect"))
183
184 while [x.active.plugin.waiting for x in self.threads if x.active].count(True) != 0:
185 sleep(0.25)
186
187 ip = self.getIP()
188
189 self.core.hookManager.beforeReconnecting(ip)
190
191 self.log.debug("Old IP: %s" % ip)
192
193 try:
194 reconn = Popen(self.core.config['reconnect']['method'], bufsize=-1, shell=True)#, stdout=subprocess.PIPE)
195 except:
196 self.log.warning(_("Failed executing reconnect script!"))
197 self.core.config["reconnect"]["activated"] = False
198 self.reconnecting.clear()
199 if self.core.debug:
200 print_exc()
201 return
202
203 reconn.wait()
204 sleep(1)
205 ip = self.getIP()
206 self.core.hookManager.afterReconnecting(ip)
207
208 self.log.info(_("Reconnected, new IP: %s") % ip)
209
210 self.reconnecting.clear()
211
212 def getIP(self):
213 """retrieve current ip"""

Callers 1

workMethod · 0.95

Calls 10

getIPMethod · 0.95
existsFunction · 0.85
PopenClass · 0.85
_Function · 0.50
isTimeReconnectMethod · 0.45
setMethod · 0.45
beforeReconnectingMethod · 0.45
clearMethod · 0.45
waitMethod · 0.45
afterReconnectingMethod · 0.45

Tested by

no test coverage detected