Receive the result of the last send. Returns ------- result: object The result of the last send. Raises ------ ChildProcessError: if the child process exited abnormally. TimeoutError: if timeout happens Exception: if other
(self)
| 271 | return ChildProcessError("Subprocess terminated") |
| 272 | |
| 273 | def recv(self): |
| 274 | """Receive the result of the last send. |
| 275 | |
| 276 | Returns |
| 277 | ------- |
| 278 | result: object |
| 279 | The result of the last send. |
| 280 | |
| 281 | Raises |
| 282 | ------ |
| 283 | ChildProcessError: if the child process exited abnormally. |
| 284 | TimeoutError: if timeout happens |
| 285 | Exception: if other exception happens during the execution. |
| 286 | """ |
| 287 | # pylint: disable=import-outside-toplevel |
| 288 | import cloudpickle |
| 289 | |
| 290 | try: |
| 291 | len_data = self._reader.read(4) |
| 292 | except OSError: |
| 293 | raise self._child_process_error() |
| 294 | |
| 295 | if len(len_data) == 0: |
| 296 | raise self._child_process_error() |
| 297 | |
| 298 | try: |
| 299 | recv_bytes = struct.unpack("<i", len_data)[0] |
| 300 | status, value = cloudpickle.loads(self._reader.read(recv_bytes)) |
| 301 | except OSError: |
| 302 | raise self._child_process_error() |
| 303 | |
| 304 | if status == StatusKind.COMPLETE: |
| 305 | return value |
| 306 | if status == StatusKind.EXCEPTION: |
| 307 | raise value |
| 308 | assert status == StatusKind.TIMEOUT |
| 309 | # kill and lazily restart the process in the next send. |
| 310 | self.kill() |
| 311 | raise TimeoutError() |
| 312 | |
| 313 | |
| 314 | class PopenPoolExecutor: |