| 13 | self.container = None |
| 14 | |
| 15 | def recreate_container(self): |
| 16 | self.shutdown() |
| 17 | |
| 18 | # Pull the Python image |
| 19 | self.client.images.pull(self.image) |
| 20 | |
| 21 | # Create a container and run an infinite loop to keep it alive |
| 22 | self.container = self.client.containers.run( |
| 23 | self.image, |
| 24 | command="bash -c 'while true; do sleep 1; done'", |
| 25 | volumes={ |
| 26 | self.full_source_path: { |
| 27 | 'bind': f"/{self.sources_dirname}", |
| 28 | 'mode': 'rw' |
| 29 | } |
| 30 | }, |
| 31 | working_dir=f"/{self.sources_dirname}", |
| 32 | stderr=True, |
| 33 | stdout=True, |
| 34 | detach=True, |
| 35 | ) |
| 36 | |
| 37 | def shutdown(self): |
| 38 | if not self.container is None: |