Skip to content

Commit d27c2dc

Browse files
committed
new CLI parameter "unordered"
1 parent 88397ce commit d27c2dc

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ options:
131131
--api-domain API domain (default api.opencagedata.com)
132132
--optional-api-params
133133
Extra parameters for each request (e.g. language=fr,no_dedupe=1)
134+
--unordered Allow the output lines to be in different order (can be faster)
134135
--limit Stop after this number of lines in the input
135136
--dry-run Read the input file but no geocoding
136137
--no-progress Display no progress bar

opencage/batch.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ async def write_one_geocoding_result(self, output, row_id, address, geocoding_re
191191
# Enforce that row are written ordered. That means we might wait for other threads
192192
# to finish a task and make the overall process slower. Alternative would be to
193193
# use a second queue, or keep some results in memory.
194-
while row_id > self.write_counter:
195-
if self.options.verbose:
196-
self.log(f"Want to write row {row_id}, but write_counter is at {self.write_counter}")
197-
await asyncio.sleep(random.uniform(0.01, 0.1))
194+
if not self.options.unordered:
195+
while row_id > self.write_counter:
196+
if self.options.verbose:
197+
self.log(f"Want to write row {row_id}, but write_counter is at {self.write_counter}")
198+
await asyncio.sleep(random.uniform(0.01, 0.1))
198199

199-
if self.options.verbose:
200-
self.log(f"Writing row {row_id}")
200+
if self.options.verbose:
201+
self.log(f"Writing row {row_id}")
201202
output.writerow(row)
202203
self.write_counter = self.write_counter + 1
203204

opencage/command_line.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def add_optional_arguments(parser):
6868
parser.add_argument("--api-domain", type=str, default="api.opencagedata.com", help="API domain (default api.opencagedata.com)", metavar='')
6969
parser.add_argument("--optional-api-params", type=comma_separated_dict_type, default="", help="Extra parameters for each request (e.g. language=fr,no_dedupe=1)", metavar='')
7070
parser.add_argument("--limit", type=int, default=0, help="Stop after this number of lines in the input", metavar='')
71+
parser.add_argument("--unordered", action="store_true", help="Allow the output lines to be in different order (can be faster)")
7172
parser.add_argument("--dry-run", action="store_true", help="Read the input file but no geocoding")
7273
parser.add_argument("--no-progress", action="store_true", help="Display no progress bar")
7374
parser.add_argument("--quiet", action="store_true", help="No progress bar and no messages")

test/cli/test_cli_args.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def test_full_argument_list():
9393
"--timeout", "2",
9494
"--retries", "1",
9595
"--dry-run",
96+
"--unordered",
9697
"--api-domain", "bulk.opencagedata.com",
9798
"--optional-api-params", "extra=1",
9899
"--no-progress",
@@ -111,6 +112,7 @@ def test_full_argument_list():
111112
assert args.timeout == 2
112113
assert args.retries == 1
113114
assert args.dry_run is True
115+
assert args.unordered is True
114116
assert args.api_domain == "bulk.opencagedata.com"
115117
assert args.optional_api_params == { "extra": "1" }
116118
assert args.no_progress is True
@@ -133,6 +135,7 @@ def test_defaults():
133135
assert args.timeout == 10
134136
assert args.retries == 10
135137
assert args.dry_run is False
138+
assert args.unordered is False
136139
assert args.api_domain == "api.opencagedata.com"
137140
assert args.optional_api_params == {}
138141
assert args.no_progress is False

0 commit comments

Comments
 (0)