AWS Lambda thread pool (lambda-thread-pool) uses multiprocessing.Pipe instead of multiprocessing.Queue. It provides the ability to perform parallel execution within the AWS lambda Python execution environment.
Project description
AWS Lambda thread pool (lambda-thread-pool)
You cannot use "multiprocessing.Queue" or "multiprocessing.Pool" within a Python Lambda environment because the Python Lambda execution environment does not support shared memory for processes.
You will see an issue if you attempt to use Pool:
{
"errorMessage": "[Errno 38] Function not implemented",
"errorType": "OSError",
"requestId": <request_id>,
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 10, in lambda_handler\n pool = Pool(10)\n",
" File \"/var/lang/lib/python3.9/multiprocessing/pool.py\", line 927, in __init__\n Pool.__init__(self, processes, initializer, initargs)\n",
" File \"/var/lang/lib/python3.9/multiprocessing/pool.py\", line 196, in __init__\n self._change_notifier = self._ctx.SimpleQueue()\n",
" File \"/var/lang/lib/python3.9/multiprocessing/context.py\", line 113, in SimpleQueue\n return SimpleQueue(ctx=self.get_context())\n",
" File \"/var/lang/lib/python3.9/multiprocessing/queues.py\", line 341, in __init__\n self._rlock = ctx.Lock()\n",
" File \"/var/lang/lib/python3.9/multiprocessing/context.py\", line 68, in Lock\n return Lock(ctx=self.get_context())\n",
" File \"/var/lang/lib/python3.9/multiprocessing/synchronize.py\", line 162, in __init__\n SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)\n",
" File \"/var/lang/lib/python3.9/multiprocessing/synchronize.py\", line 57, in __init__\n sl = self._semlock = _multiprocessing.SemLock(\n"
]
}
AWS Lambda thread pool (lambda-thread-pool) uses "multiprocessing.Pipe" instead of "multiprocessing.Queue". It provides the ability to perform parallel execution within the AWS lambda Python execution environment.
Prerequisites
- python3
- pip
- AWS Credentials
Install
pip install lambda-thread-pool
Usage
from lambda_thread_pool import LambdaThreadPool
def test_func(index, message):
print(index, message, end='\n')
return message
def lambda_handler(event, context):
pool = LambdaThreadPool()
results = []
for i in range(10):
res = pool.apply_async(test_func, (i, f'Message: {i}'))
results.append(res)
pool.join()
for result in results:
print('Result:', result.get())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lambda-thread-pool-0.0.2.tar.gz
.
File metadata
- Download URL: lambda-thread-pool-0.0.2.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a562221fe7a7a33517a5f75375fa9911f0ce877277051d8074fae31ba2b81179 |
|
MD5 | ba73dd435c994b6875b15706844097b6 |
|
BLAKE2b-256 | 04a08dc951e4403628ab3097c0be2edd8e83f0e11dcb76830554f3135dd0dbee |
File details
Details for the file lambda_thread_pool-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: lambda_thread_pool-0.0.2-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00e75842275c2391758c9ddc936aba68cdee57c0b07f1db27adf07e6591e6157 |
|
MD5 | 9e318da38815b24d196f68b74fd935c5 |
|
BLAKE2b-256 | 612561265cb54dd3f6977e1dce21dab5cfa6415b717809c51a9cf75f535196db |