MCPcopy
hub / github.com/brightio/penelope / loop

Method loop

penelope.py:1707–1849  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1705 threading.Thread(target=self.loop, name="Core").start()
1706
1707 def loop(self):
1708
1709 while self.started:
1710 try:
1711 readables, writables, _ = select(self.rlist, self.wlist, [])
1712 except (ValueError, OSError):
1713 def _valid_fd(x):
1714 try:
1715 return x.fileno() >= 0
1716 except Exception:
1717 return False
1718 self.rlist = [x for x in self.rlist if _valid_fd(x)]
1719 self.wlist = [x for x in self.wlist if _valid_fd(x)]
1720 continue
1721
1722 for readable in readables:
1723
1724 # The control queue
1725 if readable is self.control:
1726 command = self.control.get()
1727 if command:
1728 try:
1729 command()
1730 except KeyError:
1731 logger.debug("The session does not exist anymore")
1732 except Exception as e:
1733 logger.error(f"Core Control command failed: {e}")
1734 else:
1735 logger.debug("Core break")
1736 break
1737
1738 # The listeners
1739 elif readable.__class__ is TCPListener:
1740 _socket, endpoint = readable.socket.accept()
1741 if sum(1 for s in self.sessions.values() if s.ip == endpoint[0]) >= options.max_sessions:
1742 _socket.close()
1743 logger.debug(f"Rejected {endpoint}: max sessions per host ({options.max_sessions}) reached")
1744 continue
1745 thread_name = f"NewCon{endpoint}"
1746 logger.debug(f"New thread: {thread_name}")
1747 threading.Thread(target=Session, args=(_socket, *endpoint, readable), name=thread_name).start()
1748
1749 # STDIN
1750 elif readable is sys.stdin:
1751 if self.attached_session:
1752 session = self.attached_session
1753 if session.type == 'Readline':
1754 continue
1755
1756 data = os.read(sys.stdin.fileno(), options.network_buffer_size)
1757
1758 if session.subtype == 'cmd':
1759 self._cmd = data
1760
1761 if data == options.escape['sequence']:
1762 #if session.alternate_buffer:
1763 # logger.error("(!) Exit the current alternate buffer program first")
1764 #else:

Callers

nothing calls this directly

Calls 14

stdoutFunction · 0.85
getMethod · 0.80
detachMethod · 0.80
recordMethod · 0.80
messageMethod · 0.80
sendMethod · 0.80
killMethod · 0.80
removeMethod · 0.80
closeMethod · 0.45
startMethod · 0.45
readMethod · 0.45
filenoMethod · 0.45

Tested by

no test coverage detected