Repository: pytorch
Issue: Failure to set number of threads on AWS Lambda
Labels: module: cpu,triaged,module: multithreading

### 🐛 Describe the bug

When I run PyTorch in AWS Lambda via a Docker Image, I get an error when trying to set the number of threads. Example code:

`torch.set_num_threads(2)`

which results in 
```


START RequestId: 8a73bd72-6dcb-525b-bb9d-e7ce3456fde0 Version: $LATEST
--
Error in cpuinfo: failed to parse the list of possible processors in /sys/devices/system/cpu/possible
Error in cpuinfo: failed to parse the list of present processors in /sys/devices/system/cpu/present
Error in cpuinfo: failed to parse both lists of possible and present processors
/var/lang/lib/python3.9/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension:
warn(f"Failed to load image Python extension: {e}")
5
terminate called after throwing an instance of 'c10::Error'
what():  [enforce fail at ThreadPool.cc:44] cpuinfo_initialize(). cpuinfo initialization failed
frame #0: c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&, void const*) + 0x50 (0x7f95b2a2a0 in /var/lang/lib/python3.9/site-packages/torch/lib/libc10.so)
frame #1: c10::ThrowEnforceNotMet(char const*, int, char const*, char const*, void const*) + 0x50 (0x7f95b2a440 in /var/lang/lib/python3.9/site-packages/torch/lib/libc10.so)
frame #2: <unknown function> + 0x1d6cb7c (0x7f978f9b7c in /var/lang/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
frame #3: <unknown function> + 0x1d6fa34 (0x7f978fca34 in /var/lang/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
frame #4: at::set_num_threads(int) + 0x2c (0x7f9641e82c in /var/lang/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
frame #5: <unknown function> + 0x498864 (0x7f9b44d864 in /var/lang/lib/python3.9/site-packages/torch/lib/libtorch_python.so)
<omitting python frames>
Fatal Python error: Aborted
Current thread 0x0000007fa42c4010 (most recent call first):
File "/var/task/src/generator.py", line 53 in <module>
File "<frozen importlib._bootstrap>", line 228 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 850 in exec_module
File "<frozen importlib._bootstrap>", line 680 in _load_unlocked
File "<frozen importlib._bootstrap>", line 986 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1007 in _find_and_load
File "/var/task/src/job.py", line 10 in <module>
File "<frozen importlib._bootstrap>", line 228 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 850 in exec_module
File "<frozen importlib._bootstrap>", line 680 in _load_unlocked
File "<frozen importlib._bootstrap>", line 986 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1007 in _find_and_load
File "<frozen importlib._bootstrap>", line 1030 in _gcd_import
File "/var/lang/lib/python3.9/importlib/__init__.py", line 127 in import_module
File "/var/runtime/awslambdaric/bootstrap.py", line 39 in _get_handler
File "/var/runtime/awslambdaric/bootstrap.py", line 389 in run
File "/var/runtime/awslambdaric/__main__.py", line 16 in main
File "/var/runtime/bootstrap.py", line 57 in main
File "/var/runtime/bootstrap.py", line 60 in <module>
END RequestId: 8a73bd72-6dcb-525b-bb9d-e7ce3456fde0

```

It runs fine locally and on docker. 

### Versions

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 12.3 (arm64)
GCC version: Could not collect
Clang version: 13.1.6 (clang-1316.0.21.2)
CMake version: version 3.23.0-rc2
Libc version: N/A

Python version: 3.9.10 (v3.9.10:f2f3f53782, Jan 13 2022, 16:55:45)  [Clang 13.0.0 (clang-1300.0.29.30)] (64-bit runtime)
Python platform: macOS-12.3-arm64-arm-64bit
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

Versions of relevant libraries:
[pip3] mypy==0.942
[pip3] mypy-extensions==0.4.3
[conda] Could not collect

cc @VitalyFedyunin