ValueError: signal only works in main thread

jupyter notebook 无法正常运行

查看 notebook.log

报错:

ERROR:tornado.general:Uncaught exception in zmqstream callback
Traceback (most recent call last):
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 450, in _handle_events
    self._handle_recv()
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 480, in _handle_recv
    self._run_callback(callback, msg)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 432, in _run_callback
    callback(*args, **kwargs)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 233, in dispatch_shell
    self.pre_handler_hook()
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 248, in pre_handler_hook
    self.saved_sigint_handler = signal(SIGINT, default_int_handler)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
ERROR:tornado.application:Exception in callback (<zmq.sugar.socket.Socket object at 0x7f44c4d698d0>, <function wrap.<locals>.null_wrapper at 0x7f44c4d02378>)
Traceback (most recent call last):
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/tornado/ioloop.py", line 888, in start
    handler_func(fd_obj, events)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 450, in _handle_events
    self._handle_recv()
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 480, in _handle_recv
    self._run_callback(callback, msg)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 432, in _run_callback
    callback(*args, **kwargs)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 233, in dispatch_shell
    self.pre_handler_hook()
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 248, in pre_handler_hook
    self.saved_sigint_handler = signal(SIGINT, default_int_handler)
  File "/mnt/home2/zxm/anaconda3/lib/python3.6/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread


解决:

重新安装:
jupyter tornado

conda uninstall jupyter tornado
conda install jupyter tornado

如果还不行直接指定版本:

pip install "pyzmq==17.0.0" "ipykernel==4.8.2"
注意:

linux更新内核后肯能导致上述问题,需重新安装 jupyter tornado

@app.route('/get_trip_time', methods=['POST']) def get_trip_time(): data = request.get_json() method = data['method'] center_coor = data['center_coor'] t = data['t'] radius = get_radius(method, t) gtt = GetTripTime(method, center_coor, t, radius) gtt.main() return jsonify({'message': 'Trip time data collected successfully'}) @app.route('/visualize_trip_time', methods=['GET']) def visualize_trip_time(): data = pd.read_csv('time1.csv') lng = data['lng'] lat = data['lat'] time = data['time'] grid_lng, grid_lat = np.meshgrid(np.linspace(lng.min(), lng.max(), 100), np.linspace(lat.min(), lat.max(), 100)) grid_time = griddata((lng, lat), time, (grid_lng, grid_lat), method='linear') fig, ax = plt.subplots(figsize=(8, 8)) contour_plot = ax.contourf(grid_lng, grid_lat, grid_time, cmap='jet', levels=6) ax.contour(contour_plot, colors='k', linewidths=0.5) plt.colorbar(contour_plot) last_lng = lng.iloc[-1] last_lat = lat.iloc[-1] ax.scatter(last_lng, last_lat, color='green', marker='o', s=50, label='Start Point') ax.legend() plt.title('Isochrone') ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') ax.xaxis.set_major_formatter(mticker.FormatStrFormatter('%.2f')) plt.show() return jsonify({'message': 'Trip time visualization generated successfully'}) @app.route('/get_isochrone_coords', methods=['GET']) def get_isochrone_coords(): with open('contour_coords.json', 'r') as f: contour_coords = json.load(f) return jsonify(contour_coords)用rest client调用GET http://localhost:5000/visualize_trip_time时报错ValueError: signal only works in main thread of the main interpreter
07-25
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值