| 14 | print(info) |
| 15 | |
| 16 | def dirty_lock(lock_name, lock_on_count=1): |
| 17 | # this lock occurred before each round to avoid duplicate printing |
| 18 | if not hasattr(os, "getppid"): |
| 19 | return False |
| 20 | ppid = os.getppid() |
| 21 | if not ppid or ppid == os.getpid(): |
| 22 | # not sure if this gonna happen, but ASV run each round in |
| 23 | # a separate process so the lock should be based on the parent |
| 24 | # process id only |
| 25 | return False |
| 26 | lock_path = os.path.abspath(os.path.join( |
| 27 | os.path.dirname(__file__), "..", "env", lock_name) |
| 28 | ) |
| 29 | # ASV loads the 'benchmark_dir' to discover the available benchmarks |
| 30 | # the issue here is ASV doesn't capture any strings from stdout or stderr |
| 31 | # during this stage so we escape it and lock on the second increment |
| 32 | try: |
| 33 | with open(lock_path, 'a+') as f: |
| 34 | f.seek(0) |
| 35 | count, _ppid = (f.read().split() + [0, 0])[:2] |
| 36 | count, _ppid = int(count), int(_ppid) |
| 37 | if _ppid == ppid: |
| 38 | if count >= lock_on_count: |
| 39 | return True |
| 40 | count += 1 |
| 41 | else: |
| 42 | count = 0 |
| 43 | f.seek(0) |
| 44 | f.truncate() |
| 45 | f.write(f"{str(count)} {str(ppid)}") |
| 46 | except IOError: |
| 47 | pass |
| 48 | return False |
| 49 | |
| 50 | |
| 51 | # FIXME: there's no official way to provide extra information to the test log |