# Buggy code
def deserialize_graph(ser_graph, graph_cls=None):
    from google.protobuf.message import DecodeError
    from .serialize.protos.graph_pb2 import GraphDef
    from .graph import DirectedGraph

    graph_cls = graph_cls or DirectedGraph
    ser_graph_bin = to_binary(ser_graph)
    g = GraphDef()
    try:
        ser_graph = ser_graph
        g.ParseFromString(ser_graph_bin)
        return graph_cls.from_pb(g)
    except DecodeError:
        pass

    try:
        ser_graph_bin = zlib.decompress(ser_graph_bin)
        g.ParseFromString(ser_graph_bin)
        return graph_cls.from_pb(g)
    except (zlib.error, DecodeError):
        json_obj = json.loads(to_str(ser_graph))
        return graph_cls.from_json(json_obj)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "mars/lib/gipc.pyx", line 419, in mars.lib.gipc._child
target(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/deploy/local/core.py", line 211, in _start_web
web.start(event=event, block=True)
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 234, in start
self._try_start_web_server()
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 219, in _try_start_web_server
http_server_kwargs={'max_buffer_size': 2 ** 32},
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/bokeh/server/server.py", line 400, in __init__
http_server.add_sockets(sockets)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/tcpserver.py", line 166, in add_sockets
sock, self._handle_connection
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 100, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 329, in add_reader
return self._add_reader(fd, callback, *args)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 259, in _add_reader
(handle, None))
File "/Users/wenjun.swj/miniconda3/lib/python3.7/selectors.py", line 520, in register
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
AttributeError: module 'select' has no attribute 'kevent'

# Fixed code
def deserialize_graph(ser_graph, graph_cls=None):
    from google.protobuf.message import DecodeError
    from .serialize.protos.graph_pb2 import GraphDef
    from .graph import DirectedGraph

    graph_cls = graph_cls or DirectedGraph
    ser_graph_bin = to_binary(ser_graph)
    g = GraphDef()
    try:
        ser_graph = ser_graph
        g.ParseFromString(ser_graph_bin)
        return graph_cls.from_pb(g)
    except DecodeError:
        pass

    try:
        ser_graph_bin = zlib.decompress(ser_graph_bin)
        g.ParseFromString(ser_graph_bin)
        return graph_cls.from_pb(g)
    except (zlib.error, DecodeError):
        pass

    json_obj = json.loads(to_str(ser_graph))
    return graph_cls.from_json(json_obj)