1、如下代码,启动的时候python app.py会报如题的错误

app.py

#!/user/bin python
# -*- coding:utf-8 -*- import os
from datetime import timedelta
from flask import Flask, session, url_for, render_template, make_response, request, redirect
import zerorpcimport multiprocessing APP = Flask(__name__)
APP.secret_key = os.urandom(24)
APP.permanent_session_lifetime = timedelta(seconds=30 * 24 * 60 * 60)
class RPCServer(object):
def hello(self, filename):
      return filename

@APP.route('/')
@APP.route('/index')
def index():
return render_template('index.html') @APP.route('/ok.htm',methods=['GET', 'POST','HEAD'])
def ok():
return render_template('ok.htm') @APP.route('/test')
def test():
session.permanent = True
_str = ''
if 'name' in session:
_str = session['name']
if 'nick' in session:
_str += '---' + session['nick']
#print session
return _str def runWeb():
print ("start webapp")
APP.run(host='0.0.0.0', port= 5000, debug=True, threaded=True) def runRPC():
#print "start rpc"
s = zerorpc.Server(RPCServer())
s.bind("tcp://0.0.0.0:4242")
s.run() if __name__ == "__main__":
p1 = multiprocessing.Process(target = runWeb)
p2 = multiprocessing.Process(target = runRPC) p1.start()
p2.start()
p1.join()
p2.join() # p1.run()
# p2.run() # p1.join()
# p2.join()

2、错误信息:

3、查看进程情况:

4、lsof -i:4242 、lsof -i:5000查看端口情况,发现rpc服务并没有启动

5、但是如果关掉flask的debug模式,就没有问题

6、原因是:flask的debug模式会额外开启一个进程,这个进程负责监控代码是否发生变化,如果发生变化,会自动重启应用,使新修改代码立即自动生效;因此我猜想,是这个进程破坏了rpc服务的启动。

DEBUG模式下flask多开一个线程来监视项目的变化。

The first thing it does is start the main function in a new thread so it can monitor >the source files and restart the thread when they change.

参考自这篇文章http://stackoverflow.com/questions/9276078/whats-the-right-approach-for-calling-functions-after-a-flask-app-is-run

如果你想要避免加载两次,应该设置app.run(debug=True, use_reloader=False)

参考:

1、https://github.com/ipython/ipython/issues/6109

2、https://segmentfault.com/q/1010000000446372

3、

zmq.error.ZMQError: Address already in use的更多相关文章

  1. [WebRTC/JsSIP] AUDIO RTP REPORTS ERROR: [Remote Address Error!]

    问题描述: 在使用FreeSWITCH WebRTC 测试时,FS回复  502 Bad Gateway.查看FS日志 [DEBUG] switch_core_media.c:5147 AUDIO R ...

  2. Error running : Address localhost:1099 is already in use

    运行报错: Error running  : Address localhost:1099 is already in use 解决方法: 打开任务管理器,将后台的java.exe进程都关掉,再次运行 ...

  3. 关于Keil C51中“ERROR L107: ADDRESS SPACE OVERFLOW ”的总

    最近写一个关于单片机播放音乐的程序,出现如下错误: *** ERROR L107: ADDRESS SPACE OVERFLOW ... ... Program Size: data=167.6 xd ...

  4. Centos7 开机显示 ERST: Failed to get Error Log Address Range” 导致无法开机解决方法

    开机显示 ERST: Failed to get Error Log Address Range”   导致无法开机,也无法重新安装系统,解决方法:开机进入BIOS , 关闭ACPI选项即可正常开机

  5. [error]Flask Address already in use

    在Python的Flask框架下Address already in use [地址已在使用中] 出现这种错误提示, 说明你已经有一个流程绑定到默认端口(5000).如果您之前已经运行过相同的模块,则 ...

  6. keil中编译时出现*** ERROR L107: ADDRESS SPACE OVERFLOW

    解决方法: http://zhidao.baidu.com/link?url=DWTVVdALVqPtUt0sWPURD6c1eEppyu9CXocLTeRZlZlhwHOA1P1xdesqmUQNw ...

  7. ERROR: openstack Error finding address for http://10.16.37.215:9292/v1/images: [Errno 32] Broken pipe

    Try to set: no_proxy=10.16.37.215 this should help 转自: http://askubuntu.com/questions/575938/error-i ...

  8. ZMQ相关

    一般来说,做bind的是服务端,做connect的是客服端.zmq的bind和connect与我们通常的socket中bind和connect是不一样的,最起码的,我们它没有启动的先后顺序,而在我们通 ...

  9. linux系统中errno与error对照表

    1.使用了一个小程序输出所有的errno对应的error字符串,代码如下 #include <errno.h> void showError(int err){ printf(" ...

随机推荐

  1. Spring事务管理全面分析

    Spring 事务属性分析什么是事物  事务管理对于企业应用而言至关重要.它保证了用户的每一次操作都是可靠的,即便出现了异常的访问情况,也不至于破坏后台数据的完整性.就像银行的自助取款机,通常都能正常 ...

  2. VsCode使用之HTML 中 CSS Class 智能提示

    HTML 中 CSS Class 智能提示 安装插件:HTML CSS Support 设置中添加以下代码: "editor.parameterHints": true, &quo ...

  3. ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath

    问题: ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the ...

  4. 日常[splay]:水题记——普通平衡树(死亡调试)

    普通平衡树,模板的不能再模板的模板题.我调了两个小时... 早先看yyb大神的blog学习splay,看的风生水起然而没有发现,大神的坑没有填……没有rank操作和k_th操作. 只能自己摸索,问问大 ...

  5. Springboot 图标更换

    1.将自己的logo图片转为.ico格式的,命名必须为[favicon.ico] 2.将该图片直接放在src/main/resourecs目录下 3.重启项目,刷新一下浏览器缓存,就会发现图标更换了

  6. oc学习

    http://www.cnblogs.com/qingyuan/p/3524678.html

  7. KVM中存储的配置

    存储配置和启动顺序 QEMU提供了对多种块存储设备的模拟,包括IDE设备.SCSI设备.软盘.U盘.virtio磁盘等,而且对设备的启动顺序提供了灵活的配置. 1. 存储的基本配置选项 在qemu-k ...

  8. Java:追加文件内容

    文章来源:https://www.cnblogs.com/hello-tl/p/9139367.html import java.io.*; public class FileBasicOperati ...

  9. 高可用技术之keepalived原理简单了解

    Keepalived 工作原理 keepalived是以VRRP协议为实现基础的,VRRP全称Virtual Router Redundancy Protocol,即虚拟路由冗余协议. 虚拟路由冗余协 ...

  10. 简单的自动化使用--使用selenium实现学习通网站的刷慕课程序。注释空格加代码大概200行不到

    简单的自动化使用--使用selenium实现学习通网站的刷慕课程序.注释空格加代码大概200行不到 相见恨晚啊 github地址 环境Python3.6 + pycharm + chrom浏览器 + ...