Return some properties of a module/package using runtime introspection. Raise InspectError if the target couldn't be imported.
(self, package_id: str)
| 138 | self.proc.terminate() |
| 139 | |
| 140 | def get_package_properties(self, package_id: str) -> ModuleProperties: |
| 141 | """Return some properties of a module/package using runtime introspection. |
| 142 | |
| 143 | Raise InspectError if the target couldn't be imported. |
| 144 | """ |
| 145 | self.tasks.put(package_id) |
| 146 | res = self._get_from_queue() |
| 147 | if res is None: |
| 148 | # The process died; recover and report error. |
| 149 | self._start() |
| 150 | raise InspectError(f"Process died when importing {package_id!r}") |
| 151 | if isinstance(res, str): |
| 152 | # Error importing module |
| 153 | if self.counter > 0: |
| 154 | # Also try with a fresh process. Maybe one of the previous imports has |
| 155 | # corrupted some global state. |
| 156 | self.close() |
| 157 | self._start() |
| 158 | return self.get_package_properties(package_id) |
| 159 | raise InspectError(res) |
| 160 | self.counter += 1 |
| 161 | return res |
| 162 | |
| 163 | def _get_from_queue(self) -> ModuleProperties | str | None: |
| 164 | """Get value from the queue. |