Python3:如何检测是否可以使用/ dev / shm(或ProcessPoolPexecutor)?

问题描述 投票:0回答:1

我有一些可以通过多处理得到改进的代码,但是在AWS Lambda中,/dev/shm不可用,因此ProcessPoolExecutor失败,并出现了隐含的错误消息:

 File "/var/task/black.py", line 529, in reformat_many
    executor = ProcessPoolExecutor(max_workers=worker_count)
  File "/var/lang/lib/python3.7/concurrent/futures/process.py", line 556, in __init__
    pending_work_items=self._pending_work_items)
  File "/var/lang/lib/python3.7/concurrent/futures/process.py", line 165, in __init__
    super().__init__(max_size, ctx=ctx)
  File "/var/lang/lib/python3.7/multiprocessing/queues.py", line 42, in __init__
    self._rlock = ctx.Lock()
  File "/var/lang/lib/python3.7/multiprocessing/context.py", line 67, in Lock
    return Lock(ctx=self.get_context())
  File "/var/lang/lib/python3.7/multiprocessing/synchronize.py", line 162, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
  File "/var/lang/lib/python3.7/multiprocessing/synchronize.py", line 59, in __init__
    unlink_now)
OSError: [Errno 38] Function not implemented

是否有一种便携式方法可以检测到它会失败?

python-3.x
1个回答
1
投票

您可以使用try / except,但例外:https://docs.python.org/fr/3/tutorial/errors.html

© www.soinside.com 2019 - 2024. All rights reserved.