I’m using a minimal structured logger with ray/serve which is causing a PicklingError while the code is loaded by Python:
import time
import ray
from ray import serve
from fastapi import FastAPI
# https://github.com/vapor-ware/containerlog
import containerlog
from containerlog.proxy.std import patch
logger = containerlog.get_logger('__name__')
containerlog.set_level(containerlog.TRACE)
# patch all standard loggers to use containerlog
patch()
app = FastAPI()
http_options = {}
http_options["host"] = "127.0.0.1"
http_options["port"] = 8787
http_options["location"] = "HeadOnly"
http_options["num_cpus"] = 2
ray.init(address="127.0.0.1:8787", namespace="serve")
serve.start(http_options=http_options)
@serve.deployment(route_prefix="/")
@serve.ingress(app)
class Deployment:
@app.post("/test")
def this_one(self):
try:
print(1/0)
except Exception as e:
# test messages
logger.trace("Valentine's day today")
logger.debug("Debug the insects")
logger.info("Just an fyi")
logger.warn("Don't Look Up")
logger.error("Did you try to divide by zero? Yes, I did")
logger.critical("The metorite hit Earth at ...")
Deployment.deploy()
while True:
time.sleep(2)
> python badlog.py
Traceback (most recent call last):
File "C:\...\badlog.py", line 27, in <module>
class Deployment:
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\serve\api.py", line 589, in decorator
frozen_app = cloudpickle.loads(cloudpickle.dumps(app))
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\cloudpickle\cloudpickle_fast.py", line 73, in dumps
cp.dump(obj)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\cloudpickle\cloudpickle_fast.py", line 620, in dump
return Pickler.dump(self, obj)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\ray\cloudpickle\cloudpickle_fast.py", line 316, in _file_reduce
raise pickle.PicklingError(
_pickle.PicklingError: Cannot pickle files that map to tty objects