22
33from bottle import Bottle
44from wit_world .exports import HttpIncoming as BaseHttpIncoming
5- from wit_world .imports import http_body , http_resp , log
5+ from wit_world .imports import compute_runtime , http_body , http_resp , log
66from wit_world .imports .http_resp import send_downstream
77
88# Enable a bit more debug logging from the framework.
99app = Bottle ()
10- app .catchall = False # bottle backtrace causes issues; use our own.
1110
1211
1312@app .route ("/hello/<name>" )
@@ -21,13 +20,7 @@ def info():
2120 from bottle import request
2221
2322 # Get some runtime info we can test
24- vcpu_time = None
25- try :
26- from wit_world .imports import compute_runtime
27-
28- vcpu_time = compute_runtime .get_vcpu_ms ()
29- except Exception :
30- pass
23+ vcpu_time = compute_runtime .get_vcpu_ms ()
3124
3225 return {
3326 "service" : "fastly-compute-python" ,
@@ -39,18 +32,6 @@ def info():
3932 }
4033
4134
42- def print (* args ):
43- # hack to allow print locally; so far, monkeypatching
44- # sys.stdout/sys.stderr hasn't panned out, so more
45- # research required.
46- log_ep .write (" " .join (args ).encode ())
47-
48-
49- def init ():
50- global log_ep
51- log_ep = log .Endpoint .get ("" )
52-
53-
5435class StdErr :
5536 """File-like object to receive errors and direct them to our logging endpoint"""
5637
@@ -98,33 +79,4 @@ def start_response(status: str, headers: list[tuple], exc_info=None):
9879
9980class HttpIncoming (BaseHttpIncoming ):
10081 def handle (self , request , body ):
101- init ()
102- try :
103- serve_wsgi_request (request , body , app )
104- except Exception as e :
105- log_exception (e )
106-
107-
108- def log_exception (e ):
109- """Pretty-print an exception to our logging endpoint.
110-
111- Do it without callling format_exc(), which calls stat() to determine whether
112- we're in a tty and what its width is. stat() and other fd routines currently
113- crash when they try to access stdout or stderr, probably because they are
114- not in the preopens.
115- """
116- try :
117- print (f"Exception { type (e ).__name__ } - { e } " )
118- print ("--- Traceback Follows ---" )
119-
120- current_tb = e .__traceback__
121- while current_tb :
122- frame = current_tb .tb_frame
123- print (
124- f" File: { frame .f_code .co_filename } , "
125- f"Function: { frame .f_code .co_name } , "
126- f"Line: { frame .f_lineno } "
127- )
128- current_tb = current_tb .tb_next
129- except Exception as e2 :
130- print (f"print_exc failed { e2 } " )
82+ serve_wsgi_request (request , body , app )
0 commit comments