def write_packet(sock, data, already_pickled=False): """Write *data* to socket *sock*""" if already_pickled: sent_data = data else: sent_data = pickle.dumps(data, PICKLE_HIGHEST_PROTOCOL) sent_data = struct.pack("l", len(sent_data)) + sent_data nsend = len(sent_data) while nsend > 0: nsend -= temp_fail_retry(socket.error, sock.send, sent_data)
def run(self): self.ipython_shell = None while True: output = pickle.dumps(None, PICKLE_HIGHEST_PROTOCOL) glbs = self.mglobals() try: if DEBUG_MONITOR: logging.debug("****** Introspection request /Begin ******") command = PACKET_NOT_RECEIVED try: timeout = self.timeout if self.auto_refresh else None command = read_packet(self.i_request, timeout=timeout) if command is None: continue timed_out = False except socket.timeout: timed_out = True except struct.error: # This should mean that Spyder GUI has crashed if DEBUG_MONITOR: logging.debug("struct.error -> quitting monitor") break if timed_out: if DEBUG_MONITOR: logging.debug("connection timed out -> updating remote view") self.update_remote_view() if DEBUG_MONITOR: logging.debug("****** Introspection request /End ******") continue if DEBUG_MONITOR: logging.debug("command: %r" % command) lcls = self.mlocals() result = eval(command, glbs, lcls) if DEBUG_MONITOR: logging.debug(" result: %r" % result) if self.pdb_obj is None: lcls["_"] = result # old com implementation: (see solution (1) in Issue 434) output = pickle.dumps(result, PICKLE_HIGHEST_PROTOCOL) # # new com implementation: (see solution (2) in Issue 434) # output = pickle.dumps((command, result), # PICKLE_HIGHEST_PROTOCOL) except SystemExit: break except: if DEBUG_MONITOR: logging.debug("error!") log_last_error(LOG_FILENAME, command) finally: try: if DEBUG_MONITOR: logging.debug("updating remote view") if self.refresh_after_eval: self.update_remote_view() self.refresh_after_eval = False if DEBUG_MONITOR: logging.debug("sending result") logging.debug("****** Introspection request /End ******") if command is not PACKET_NOT_RECEIVED: if write_packet is None: # This may happen during interpreter shutdown break else: write_packet(self.i_request, output, already_pickled=True) except AttributeError as error: if "'NoneType' object has no attribute" in str(error): # This may happen during interpreter shutdown break else: raise except TypeError as error: if "'NoneType' object is not subscriptable" in str(error): # This may happen during interpreter shutdown break else: raise self.i_request.close() self.n_request.close()
def run(self): self.ipython_shell = None while True: output = pickle.dumps(None, PICKLE_HIGHEST_PROTOCOL) glbs = self.mglobals() try: if DEBUG_MONITOR: logging.debug("****** Introspection request /Begin ******") command = PACKET_NOT_RECEIVED try: timeout = self.timeout if self.auto_refresh else None command = read_packet(self.i_request, timeout=timeout) if command is None: continue timed_out = False except socket.timeout: timed_out = True except struct.error: # This should mean that Spyder GUI has crashed if DEBUG_MONITOR: logging.debug("struct.error -> quitting monitor") break if timed_out: if DEBUG_MONITOR: logging.debug( "connection timed out -> updating remote view") self.update_remote_view() if DEBUG_MONITOR: logging.debug( "****** Introspection request /End ******") continue if DEBUG_MONITOR: logging.debug("command: %r" % command) lcls = self.mlocals() result = eval(command, glbs, lcls) if DEBUG_MONITOR: logging.debug(" result: %r" % result) if self.pdb_obj is None: lcls["_"] = result # old com implementation: (see solution (1) in Issue 434) output = pickle.dumps(result, PICKLE_HIGHEST_PROTOCOL) # # new com implementation: (see solution (2) in Issue 434) # output = pickle.dumps((command, result), # PICKLE_HIGHEST_PROTOCOL) except SystemExit: break except: if DEBUG_MONITOR: logging.debug("error!") log_last_error(LOG_FILENAME, command) finally: try: if DEBUG_MONITOR: logging.debug("updating remote view") if self.refresh_after_eval: self.update_remote_view() self.refresh_after_eval = False if DEBUG_MONITOR: logging.debug("sending result") logging.debug( "****** Introspection request /End ******") if command is not PACKET_NOT_RECEIVED: if write_packet is None: # This may happen during interpreter shutdown break else: write_packet(self.i_request, output, already_pickled=True) except AttributeError as error: if "'NoneType' object has no attribute" in str(error): # This may happen during interpreter shutdown break else: raise except TypeError as error: if "'NoneType' object is not subscriptable" in str(error): # This may happen during interpreter shutdown break else: raise self.i_request.close() self.n_request.close()