Execute while holding the lock.
(self, app_path, action, args, kwargs)
| 99 | return self._execute_locked(app_path, action, args, kwargs) |
| 100 | |
| 101 | def _execute_locked(self, app_path, action, args, kwargs): |
| 102 | """Execute while holding the lock.""" |
| 103 | # Ensure connected |
| 104 | if self._sock is None: |
| 105 | self.connect() |
| 106 | |
| 107 | # Build request |
| 108 | request_id = str(uuid.uuid4()) |
| 109 | request = make_request( |
| 110 | request_id=request_id, |
| 111 | app_path=app_path, |
| 112 | action=action, |
| 113 | args=args, |
| 114 | kwargs=kwargs |
| 115 | ) |
| 116 | |
| 117 | try: |
| 118 | # Send request |
| 119 | DirtyProtocol.write_message(self._sock, request) |
| 120 | |
| 121 | # Receive response |
| 122 | response = DirtyProtocol.read_message(self._sock) |
| 123 | |
| 124 | # Handle response |
| 125 | return self._handle_response(response) |
| 126 | except socket.timeout: |
| 127 | self._close_socket() |
| 128 | raise DirtyTimeoutError( |
| 129 | "Timeout waiting for dirty app response", |
| 130 | timeout=self.timeout |
| 131 | ) |
| 132 | except Exception as e: |
| 133 | self._close_socket() |
| 134 | if isinstance(e, DirtyError): |
| 135 | raise |
| 136 | raise DirtyConnectionError(f"Communication error: {e}") from e |
| 137 | |
| 138 | def stream(self, app_path, action, *args, **kwargs): |
| 139 | """ |
no test coverage detected