Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python gevent.monkey.patch\u all()之后的最大用户连接数_Python_Mysql_Monkeypatching_Gevent Socketio_Greenlets - Fatal编程技术网

Python gevent.monkey.patch\u all()之后的最大用户连接数

Python gevent.monkey.patch\u all()之后的最大用户连接数,python,mysql,monkeypatching,gevent-socketio,greenlets,Python,Mysql,Monkeypatching,Gevent Socketio,Greenlets,我正在使用gevent socketio v0.13.8作为基于django的web应用程序上的聊天应用程序。我的数据库是MySql,最大用户连接数=1500。我的套接字服务器使用python守护进程进行守护。我在使用socket服务器时没有使用monkey补丁,它运行良好,除非greenlet上出现错误,否则所有系统都会在SystemExit中出现故障,无法再建立连接。解决方案是重新启动所有服务器 但是,我不想每次都重新启动服务器。最后我想出了猴子修补的主意。我不知道这是否与我的问题有关,但我

我正在使用gevent socketio v0.13.8作为基于django的web应用程序上的聊天应用程序。我的数据库是MySql,最大用户连接数=1500。我的套接字服务器使用python守护进程进行守护。我在使用socket服务器时没有使用monkey补丁,它运行良好,除非greenlet上出现错误,否则所有系统都会在SystemExit中出现故障,无法再建立连接。解决方案是重新启动所有服务器

但是,我不想每次都重新启动服务器。最后我想出了猴子修补的主意。我不知道这是否与我的问题有关,但我希望我的套接字服务器能够运行,即使未处理的异常导致绿地上的SystemExit

然后我在服务器启动函数中使用了gevent.monkey.patch_all()。我现在的主要问题是:在3-4次连接之后,MySql会导致以下错误:

User xxx already has more than 'max_user_connections' active connections
在mysql服务器中,最大用户连接变量设置为1500。我认为有些东西在greenlets中创建了到数据库的新连接

顺便说一句,当我使用以下命令时,max_用户_连接错误不会出现:

monkey.patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=True, ssl=True, httplib=True, aggressive=True)
而不是:

monkey.patch_all()
有没有一种方法可以使用monkey补丁而不出现此错误?如果我忘记提供有关问题定义的任何信息,请让我知道,我会立即更新

这是我的守护服务器代码:

class App():

    def __init__(self):
        self.stdin_path = 'xxx.txt'
        self.stdout_path = 'xxx.txt'
        self.stderr_path = 'xxx.txt'
        self.pidfile_path =  'xxx.pid'
        self.pidfile_timeout = 5

    def run(self):
        from socketio.server import SocketIOServer
        from gevent import monkey
        monkey.patch_all()
        while True:
            try:
                bind = ("xx.xx.xx.xx", xxxx)
                handler = get_handler()
                server = SocketIOServer(bind, handler, resource="socket.io",policy_server=False)
                server.serve_forever()
            except:
                server.kill()
app = App()
logger = logging.getLogger("DaemonLog")
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.FileHandler("xxx.log")
handler.setFormatter(formatter)
logger.addHandler(handler)

daemon_runner = runner.DaemonRunner(app)
daemon_runner.daemon_context.files_preserve=[handler.stream]
daemon_runner.do_action()

我已在以下位置找到问题的解决方案:

它实际上与Greenlet的非封闭数据库连接有关。 在我的命名空间类中添加了一个类似的异常处理程序装饰器之后,我没有看到max\u user\u连接错误

from django.db import close_old_connections  # Django 1.6
class MyNamespace(BaseNamespace):
    ...
    def exception_handler_decorator(self, fun):
        def wrap(*args, **kwargs):
            try:
                return fun(*args, **kwargs)
            finally:
                close_old_connections()
        return wrap
    ...