-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathhandler.py
More file actions
43 lines (32 loc) · 1.38 KB
/
handler.py
File metadata and controls
43 lines (32 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def handler(event, context):
"""Lambda handler that will get invoked by the LocalStack runtime"""
# Print the incoming invocation event.
print(event)
# Return the incoming invocation event.
return event
def wait_for_debug_client(port: int=19891, timeout: int=3600):
"""Utility function to enable debugging with Visual Studio Code"""
import time, threading
import sys, glob
sys.path.append(glob.glob(".venv/lib/python*/site-packages")[0])
import debugpy
if not hasattr(wait_for_debug_client, "_debugpy_listening"):
wait_for_debug_client._debugpy_listening = False
if not wait_for_debug_client._debugpy_listening:
try:
debugpy.listen(("0.0.0.0", port))
wait_for_debug_client._debugpy_listening = True
print(f"debugpy is now listening on port {port}")
except RuntimeError as e:
print(f"debugpy.listen() failed or already active: {e}")
if not debugpy.is_client_connected():
print("Waiting for client to attach debugger...")
def cancel_wait():
time.sleep(timeout)
print("Canceling debug wait task after timeout...")
debugpy.wait_for_client.cancel()
threading.Thread(target=cancel_wait, daemon=True).start()
debugpy.wait_for_client()
else:
print("Debugger already attached.")
wait_for_debug_client()