(options, mode, urls)
| 124 | |
| 125 | |
| 126 | def main(options, mode, urls): |
| 127 | start_time = time.time() |
| 128 | errors = 0 |
| 129 | if mode == "parallel": |
| 130 | nrequests_per_thread = options.nrequests // options.nthreads |
| 131 | |
| 132 | if options.verbose: |
| 133 | print( |
| 134 | "Getting {} {} times total in {} threads, " "{} times per thread".format( |
| 135 | urls, |
| 136 | nrequests_per_thread * options.nthreads, |
| 137 | options.nthreads, |
| 138 | nrequests_per_thread, |
| 139 | ) |
| 140 | ) |
| 141 | threads = [ |
| 142 | URLGetterThread(options, urls, nrequests_per_thread) for _ in range(options.nthreads) |
| 143 | ] |
| 144 | |
| 145 | for t in threads: |
| 146 | t.start() |
| 147 | |
| 148 | for t in threads: |
| 149 | t.join() |
| 150 | |
| 151 | errors = sum([t.errors for t in threads]) |
| 152 | nthreads_with_errors = len([t for t in threads if t.errors]) |
| 153 | if nthreads_with_errors: |
| 154 | print("%d threads had errors! %d errors in total" % (nthreads_with_errors, errors)) |
| 155 | else: |
| 156 | assert mode == "serial" |
| 157 | if options.verbose: |
| 158 | print(f"Getting {urls} {options.nrequests} times in one thread") |
| 159 | |
| 160 | for i in range(1, options.nrequests + 1): |
| 161 | try: |
| 162 | get(urls) |
| 163 | except Exception as e: |
| 164 | print(e) |
| 165 | if not options.continue_: |
| 166 | sys.exit(1) |
| 167 | |
| 168 | errors += 1 |
| 169 | |
| 170 | if options.verbose and not i % 1000: |
| 171 | print(i) |
| 172 | |
| 173 | if errors: |
| 174 | print("%d errors!" % errors) |
| 175 | |
| 176 | if options.verbose: |
| 177 | print("Completed in %.2f seconds" % (time.time() - start_time)) |
| 178 | |
| 179 | if errors: |
| 180 | # Failure |
| 181 | sys.exit(1) |
| 182 | |
| 183 |
no test coverage detected