Repository: PyGithub/PyGithub

Issue:
1.58 is not compatible with AWS Lambda
1.58 introduces a dependency on multiprocessing.RLock which it not compatible with AWS Lambda. multiprocessing.SemLock (used by RLock in Requester.py) will raise OSError [Errno 38] Function not implemented. This is caused by /dev/shm not being available in AWS Lamba.

I don't have a workaround and downgraded to 1.57 which works fine.


Discussion:
Confirmed. This broke our Lambda deployments too. Thanks for reporting.
This broke our Lambda deployments as well..
Can you please provide the full stacktrace?

Is the error thrown on `import`, when calling `RLock()` or when entering the `with` context.
It's when calling `RLock()`. I'll find the stacktrace in a few minutes.
```
    2023-02-20T21:17:16.480+00:00   File "/var/task/github/MainClass.py", line 122, in __init__
    2023-02-20T21:17:16.480+00:00   self.__requester = Requester(
    2023-02-20T21:17:16.480+00:00   File "/var/task/github/Requester.py", line 316, in __init__
    2023-02-20T21:17:16.480+00:00   self.__auth_lock = RLock()
    2023-02-20T21:17:16.480+00:00   File "/var/lang/lib/python3.9/multiprocessing/context.py", line 73, in RLock
    2023-02-20T21:17:16.480+00:00   return RLock(ctx=self.get_context())
    2023-02-20T21:17:16.480+00:00   File "/var/lang/lib/python3.9/multiprocessing/synchronize.py", line 187, in __init__
    2023-02-20T21:17:16.480+00:00   SemLock.__init__(self, RECURSIVE_MUTEX, 1, 1, ctx=ctx)
    2023-02-20T21:17:16.480+00:00   File "/var/lang/lib/python3.9/multiprocessing/synchronize.py", line 57, in __init__
    2023-02-20T21:17:16.480+00:00   sl = self._semlock = _multiprocessing.SemLock(
    2023-02-20T21:17:16.480+00:00   OSError: [Errno 38] Function not implemented
    ```
I'd suggest to wrap `self.__auth_lock = RLock()` with a try block and fall back assigning an no-op context manager to `self.__auth_lock`. This way the usage of the lock in `with self.__auth_lock:` will still work, though there is no locking. Does not hurt since there is no concurrency anyway.

Someone here volunteering to draft a PR for this?
I faced a similar issue in AWS Lambda after upgrading to 1.58. In my case I got a `FileNotFoundError` exception when calling the main class `Github`:

```
  File ... line 42, in create_pull_request
    gh = Github(gh_access_token)
  File \"/home/app/github/MainClass.py\", line 122, in __init__
    self.__requester = Requester(
  File \"/home/app/github/Requester.py\", line 316, in __init__
    self.__auth_lock = RLock()
  File \"/usr/lib/python3.10/multiprocessing/context.py\", line 73, in RLock
    return RLock(ctx=self.get_context())
  File \"/usr/lib/python3.10/multiprocessing/synchronize.py\", line 187, in __init__
    SemLock.__init__(self, RECURSIVE_MUTEX, 1, 1, ctx=ctx)
  File \"/usr/lib/python3.10/multiprocessing/synchronize.py\", line 57, in __init__
    sl = self._semlock = _multiprocessing.SemLock(
FileNotFoundError: [Errno 2] No such file or directory"
```
Confirmed this broke our lambda too, thank you for reporting 

Resolving patch:
diff --git a/github/Requester.py b/github/Requester.py
--- a/github/Requester.py
+++ b/github/Requester.py
@@ -60,7 +60,6 @@
 import time
 import urllib
 from io import IOBase
-from multiprocessing import RLock
 
 import requests
 
@@ -314,8 +313,6 @@ def __init__(
         self.__app_auth = app_auth
         self.__base_url = base_url
 
-        self.__auth_lock = RLock()
-
         if password is not None:
             login = login_or_token
             b64 = (
@@ -388,10 +385,9 @@ def _refresh_token_if_needed(self) -> None:
         """Get a new access token from the GitHub app installation if the one we have is about to expire"""
         if not self.__installation_authorization:
             return
-        with self.__auth_lock:
-            if self._must_refresh_token():
-                logging.debug("Refreshing access token")
-                self._refresh_token()
+        if self._must_refresh_token():
+            logging.debug("Refreshing access token")
+            self._refresh_token()
 
     def _refresh_token(self) -> None:
         """In the context of a GitHub app, refresh the access token"""


Test patch: