Skip to content

Commit 68526b3

Browse files
committed
Switch from n_threads to n_processes
1 parent e84aee7 commit 68526b3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

qgis_processing/extractPtsAlgorithm.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
from .qgisUtils import feature_from_gdf_row
2929

3030

31+
CPU_COUNT = os.cpu_count()
32+
33+
3134
class ExtractODPtsAlgorithm(TrajectoriesAlgorithm):
3235
ORIGIN_PTS = "ORIGIN_PTS"
3336
DESTINATIONS_PTS = "DESTINATIONS_PTS"
@@ -203,7 +206,7 @@ def processTc(self, tc, parameters, context):
203206
min_duration = self.parameterAsString(parameters, self.MIN_DURATION, context)
204207
min_duration = pd.Timedelta(min_duration).to_pytimedelta()
205208

206-
gdf = TrajectoryStopDetector(tc, n_threads=os.cpu_count()).get_stop_points(
209+
gdf = TrajectoryStopDetector(tc, n_processes=CPU_COUNT).get_stop_points(
207210
max_diameter=max_diameter, min_duration=min_duration
208211
)
209212
gdf = gdf.convert_dtypes()

qgis_processing/trajectoriesAlgorithm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"a": 3600 * 24 * 365,
3636
}
3737

38+
CPU_COUNT = os.cpu_count()
39+
3840

3941
class TrajectoriesAlgorithm(QgsProcessingAlgorithm):
4042
INPUT = "INPUT"
@@ -156,9 +158,8 @@ def create_tc(self, parameters, context):
156158
)
157159

158160
if self.add_metrics:
159-
cpus = os.cpu_count()
160-
tc.add_speed(units=tuple(self.speed_units), overwrite=True, n_threads=cpus)
161-
tc.add_direction(overwrite=True, n_threads=cpus)
161+
tc.add_speed(units=tuple(self.speed_units), overwrite=True, n_processes=CPU_COUNT)
162+
tc.add_direction(overwrite=True, n_processes=CPU_COUNT)
162163
return tc, crs
163164

164165
def get_pt_fields(self, fields_to_add=[]):

0 commit comments

Comments
 (0)