forked from Rust-related/RustPython
Merge pull request #1261 from kluid/master
Implemented stdlib function 'os.cpu_count()'
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -743,6 +743,14 @@ name = "num-traits"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
version = "0.2.2"
|
||||
@@ -1136,6 +1144,7 @@ dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro-hack 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pwd 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -2060,6 +2069,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
|
||||
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
|
||||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||
"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
|
||||
"checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409"
|
||||
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
||||
"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
|
||||
|
||||
@@ -78,3 +78,4 @@ flate2 = { version = "1.0", features = ["zlib"], default-features = false }
|
||||
libz-sys = "1.0.25"
|
||||
gethostname = "0.2.0"
|
||||
subprocess = "0.1.18"
|
||||
num_cpus = "1.0"
|
||||
|
||||
@@ -6,6 +6,8 @@ use std::io::{self, Error, ErrorKind, Read, Write};
|
||||
use std::time::{Duration, SystemTime};
|
||||
use std::{env, fs};
|
||||
|
||||
use num_cpus;
|
||||
|
||||
#[cfg(unix)]
|
||||
use nix::errno::Errno;
|
||||
#[cfg(all(unix, not(target_os = "redox")))]
|
||||
@@ -759,6 +761,11 @@ fn os_getpid(vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.new_int(pid)
|
||||
}
|
||||
|
||||
fn os_cpu_count(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let cpu_count = num_cpus::get();
|
||||
vm.new_int(cpu_count)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn os_getppid(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let ppid = unistd::getppid().as_raw();
|
||||
@@ -1002,7 +1009,8 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
"R_OK" => ctx.new_int(4),
|
||||
"W_OK" => ctx.new_int(2),
|
||||
"X_OK" => ctx.new_int(1),
|
||||
"getpid" => ctx.new_rustfunc(os_getpid)
|
||||
"getpid" => ctx.new_rustfunc(os_getpid),
|
||||
"cpu_count" => ctx.new_rustfunc(os_cpu_count)
|
||||
});
|
||||
|
||||
for support in support_funcs {
|
||||
|
||||
Reference in New Issue
Block a user