1 Answer
- Newest
- Most votes
- Most comments
0
Multiprocessing is a part of python standard library , you don't need to make any changes to ec2 instance setting, can you also post errors if you encountered any?
I was able to test using the same ec2 instance type c6i.xlarge please see the code below
running the python file directly
python3 mptest.py
[1, 4, 9]
[ec2-user@ip-172-31-18-12 python-docker]$
I previously built the docker container using sudo docker build -t python-imagename . and here is the docker run output
sudo docker run python-imagename
[1, 4, 9]
this is the file I use from referenced python documentation
[ec2-user@ip-172-31-18-12 python-docker]$ cat mptest.py
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))
this is my dockerfile
cat dockerfile
FROM python:3.9
# Or any preferred Python version.
ADD mptest.py .
CMD ["python3", "./mptest.py"]
HTH
Thanks
answered 2 years ago
Relevant content
- asked 3 years ago
- asked 2 years ago
