| 2811 | return interpid |
| 2812 | |
| 2813 | def import_in_subinterp(self, interpid=None, *, |
| 2814 | postscript=None, |
| 2815 | postcleanup=False, |
| 2816 | ): |
| 2817 | name = self.NAME |
| 2818 | |
| 2819 | if postcleanup: |
| 2820 | import_ = 'import _testinternalcapi' if interpid is None else '' |
| 2821 | postcleanup = f''' |
| 2822 | {import_} |
| 2823 | mod._clear_globals() |
| 2824 | _testinternalcapi.clear_extension(name, {self.ORIGIN!r}) |
| 2825 | ''' |
| 2826 | |
| 2827 | try: |
| 2828 | pipe = self._pipe |
| 2829 | except AttributeError: |
| 2830 | r, w = pipe = self._pipe = os.pipe() |
| 2831 | self.addCleanup(os.close, r) |
| 2832 | self.addCleanup(os.close, w) |
| 2833 | |
| 2834 | snapshot = TestSinglePhaseSnapshot.from_subinterp( |
| 2835 | name, |
| 2836 | interpid, |
| 2837 | pipe=pipe, |
| 2838 | import_first=True, |
| 2839 | postscript=postscript, |
| 2840 | postcleanup=postcleanup, |
| 2841 | ) |
| 2842 | |
| 2843 | return types.SimpleNamespace( |
| 2844 | name=name, |
| 2845 | module=None, |
| 2846 | snapshot=snapshot, |
| 2847 | ) |
| 2848 | |
| 2849 | # checks |
| 2850 | |