Reads from an underlying Reader class, but may stop due to additional constraints. Build and return network(s) to read data from a Reader with additional constraints, depending on which derived class is used. Derived classes implement setup_limited and check_limiter_
(self, local_init_net, local_finish_net)
| 339 | self.setup_limiter(global_init_net, global_finish_net) |
| 340 | |
| 341 | def read_ex(self, local_init_net, local_finish_net): |
| 342 | """Reads from an underlying Reader class, but may stop due to additional |
| 343 | constraints. |
| 344 | |
| 345 | Build and return network(s) to read data from a Reader with |
| 346 | additional constraints, depending on which derived class is used. |
| 347 | Derived classes implement setup_limited and check_limiter_condition |
| 348 | which determine the nature of the constraint imposed on the reader, |
| 349 | e.g. iteration limits or time limit. |
| 350 | |
| 351 | Args: |
| 352 | local_init_net: A net invoked at task instance init time (Once per |
| 353 | parallel thread). |
| 354 | local_finish_net: A net invoked at task instance cleanup time (Once |
| 355 | per parallel thread). |
| 356 | """ |
| 357 | |
| 358 | # Check if limiting constraint is met. |
| 359 | stop_condition_net = core.Net('limited_reader_condition') |
| 360 | should_stop = self.check_limiter_condition(stop_condition_net) |
| 361 | |
| 362 | # Call original reader. |
| 363 | nets, local_data_finished, fields = self.reader.read_ex( |
| 364 | local_init_net, local_finish_net) |
| 365 | self._set_schema(self.reader._schema) |
| 366 | |
| 367 | # Check if original reader is done. |
| 368 | check_done_net = core.Net('limited_reader_post') |
| 369 | # Copy to the same blob as the counter output to trigger reader |
| 370 | # stopping - this is ok because execution will check should_stop_blob |
| 371 | # after every single operation, so it has already been checked on this |
| 372 | # iteration by this point. |
| 373 | check_done_net.Copy(local_data_finished, should_stop) |
| 374 | # Update externally-accessible flag indicating if reader is done |
| 375 | check_done_net.Or([self._data_finished, local_data_finished], |
| 376 | [self._data_finished]) |
| 377 | |
| 378 | return [stop_condition_net] + nets + [check_done_net], should_stop, fields |
| 379 | |
| 380 | def setup_limiter(self, global_init_net, global_finish_net): |
| 381 | """Configure task level init/cleanup nets required to implement limit |
nothing calls this directly
no test coverage detected