File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ pub mod types;
16
16
use anyhow:: { anyhow, Result } ;
17
17
use pyo3:: exceptions:: PyValueError ;
18
18
use pyo3:: prelude:: * ;
19
+ use pyo3:: types:: PyType ;
20
+ use rayon:: ThreadPoolBuilder ;
19
21
use std:: collections:: HashMap ;
20
22
use std:: path:: { Component , Path , PathBuf , MAIN_SEPARATOR } ;
21
23
use walkdir:: WalkDir ;
@@ -193,6 +195,19 @@ impl Reclass {
193
195
Inventory :: render ( self )
194
196
. map_err ( |e| PyValueError :: new_err ( format ! ( "Error while rendering inventory: {e}" ) ) )
195
197
}
198
+
199
+ /// Configures the number of threads to use when rendering the full inventory. Calling the
200
+ /// method with `count=0` will configure the thread pool to have one thread per logical core of
201
+ /// the system.
202
+ ///
203
+ /// Note that this method should only be called once and will print a diagnostic message if
204
+ /// called again.
205
+ #[ classmethod]
206
+ pub fn set_thread_count ( _cls : & PyType , count : usize ) {
207
+ if let Err ( e) = ThreadPoolBuilder :: new ( ) . num_threads ( count) . build_global ( ) {
208
+ eprintln ! ( "While initializing global thread pool: {e}" ) ;
209
+ }
210
+ }
196
211
}
197
212
198
213
impl Default for Reclass {
You can’t perform that action at this time.
0 commit comments