|
4 | 4 | import functools
|
5 | 5 | import itertools
|
6 | 6 | import logging
|
| 7 | +import threading |
7 | 8 | import os
|
8 | 9 | import re
|
9 | 10 | import shutil
|
@@ -207,7 +208,8 @@ def __repr__(self):
|
207 | 208 |
|
208 | 209 | @abstractmethod
|
209 | 210 | def run(self,
|
210 |
| - runtimeContext # type: RuntimeContext |
| 211 | + runtimeContext, # type: RuntimeContext |
| 212 | + tmpdir_lock=None # type: threading.Lock |
211 | 213 | ): # type: (...) -> None
|
212 | 214 | pass
|
213 | 215 |
|
@@ -421,11 +423,18 @@ def get_tree_mem_usage(memory_usage):
|
421 | 423 |
|
422 | 424 | class CommandLineJob(JobBase):
|
423 | 425 | def run(self,
|
424 |
| - runtimeContext # type: RuntimeContext |
| 426 | + runtimeContext, # type: RuntimeContext |
| 427 | + tmpdir_lock=None # type: threading.Lock |
425 | 428 | ): # type: (...) -> None
|
426 | 429 |
|
427 |
| - if not os.path.exists(self.tmpdir): |
428 |
| - os.makedirs(self.tmpdir) |
| 430 | + if tmpdir_lock: |
| 431 | + with tmpdir_lock: |
| 432 | + if not os.path.exists(self.tmpdir): |
| 433 | + os.makedirs(self.tmpdir) |
| 434 | + else: |
| 435 | + if not os.path.exists(self.tmpdir): |
| 436 | + os.makedirs(self.tmpdir) |
| 437 | + |
429 | 438 | self._setup(runtimeContext)
|
430 | 439 |
|
431 | 440 | env = self.environment
|
@@ -587,9 +596,18 @@ def add_volumes(self,
|
587 | 596 | pathmapper.update(
|
588 | 597 | key, new_path, vol.target, vol.type, vol.staged)
|
589 | 598 |
|
590 |
| - def run(self, runtimeContext): # type: (RuntimeContext) -> None |
591 |
| - if not os.path.exists(self.tmpdir): |
592 |
| - os.makedirs(self.tmpdir) |
| 599 | + def run(self, |
| 600 | + runtimeContext, # type: RuntimeContext |
| 601 | + tmpdir_lock=None # type: threading.Lock |
| 602 | + ): # type: (...) -> None |
| 603 | + if tmpdir_lock: |
| 604 | + with tmpdir_lock: |
| 605 | + if not os.path.exists(self.tmpdir): |
| 606 | + os.makedirs(self.tmpdir) |
| 607 | + else: |
| 608 | + if not os.path.exists(self.tmpdir): |
| 609 | + os.makedirs(self.tmpdir) |
| 610 | + |
593 | 611 | (docker_req, docker_is_req) = self.get_requirement("DockerRequirement")
|
594 | 612 | self.prov_obj = runtimeContext.prov_obj
|
595 | 613 | img_id = None
|
|
0 commit comments