A problem with connection pool
I'm confused, what is the error and why is it an error in the connection pool? Seems to me to be an error in gunicorn/gevent.
 Peewee is using pymysql and it's connection pooling(playhouse.pool) wants
to create new connection. Python socket and threading replaced by gevent
monkey because of workers of gunicorn being Gevent. Isn't it?!
On Jun 12, 2015 9:14 PM, "Charles Leifer" notifications@github.com wrote:

> I'm confused, what is the error and why is it an error in the connection
> pool? Seems to me to be an error in gunicorn/gevent.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/coleifer/peewee/issues/624#issuecomment-111552678.
 This error raised at web requesting, there we have new connection and at
tearing down that new will be closed.
On Jun 13, 2015 12:48 AM, "S.Mohammad Emami Razavi" emamirazavi@gmail.com
wrote:

> Peewee is using pymysql and it's connection pooling(playhouse.pool) wants
> to create new connection. Python socket and threading replaced by gevent
> monkey because of workers of gunicorn being Gevent. Isn't it?!
> On Jun 12, 2015 9:14 PM, "Charles Leifer" notifications@github.com
> wrote:
> 
> > I'm confused, what is the error and why is it an error in the connection
> > pool? Seems to me to be an error in gunicorn/gevent.
> > 
> > —
> > Reply to this email directly or view it on GitHub
> > https://github.com/coleifer/peewee/issues/624#issuecomment-111552678.
 I am still not sure how this is a peewee issue.
 @coleifer  If it's possible keep this issue open for now. I will send it to the gevent on github and i wait for feedback. https://github.com/gevent/gevent/issues/573
 See https://github.com/gevent/gevent/issues/573 again
I think(based on traceback) this problem belongs to pymysql+gevent or my code not peewee.
Please close it if you are conviced.
 Feel free to comment if you have new info indicating peewee as the cause.

```
Jun 12 10:23:52 www.example.com gunicorn[4763]: [2015-06-12 10:23:52 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:53 www.example.com gunicorn[4763]: [2015-06-12 10:23:53 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:54 www.example.com gunicorn[4763]: [2015-06-12 10:23:53 +0000] [2876] [DEBUG] GET /inbound
Jun 12 10:23:54 www.example.com gunicorn[4763]: [2015-06-12 10:23:53 +0000] [2876] [ERROR] Error handling request
Jun 12 10:23:54 www.example.com gunicorn[4763]: Traceback (most recent call last):
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/gunicorn/workers/async.py", line 52, in handle
Jun 12 10:23:54 www.example.com gunicorn[4763]: self.handle_request(listener_name, req, client, addr)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 159, in handle_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: super(GeventWorker, self).handle_request(*args)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/gunicorn/workers/async.py", line 105, in handle_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: respiter = self.wsgi(environ, resp.start_response)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
Jun 12 10:23:54 www.example.com gunicorn[4763]: return self.wsgi_app(environ, start_response)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
Jun 12 10:23:54 www.example.com gunicorn[4763]: response = self.make_response(self.handle_exception(e))
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
Jun 12 10:23:54 www.example.com gunicorn[4763]: reraise(exc_type, exc_value, tb)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
Jun 12 10:23:54 www.example.com gunicorn[4763]: response = self.full_dispatch_request()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: rv = self.handle_user_exception(e)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
Jun 12 10:23:54 www.example.com gunicorn[4763]: reraise(exc_type, exc_value, tb)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1473, in full_dispatch_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: rv = self.preprocess_request()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1666, in preprocess_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: rv = func()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/local/src/aaron/lib/myapp/webserver.py", line 96, in before_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: g.db.connect()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/local/src/aaron/lib/myapp/database.py", line 77, in connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: super(MyPooledMySQLDatabase, self).connect()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/peewee.py", line 2944, in connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: **self.connect_kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/playhouse/pool.py", line 108, in _connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: conn = super(PooledDatabase, self)._connect(*args, **kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/peewee.py", line 3399, in _connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: return mysql.connect(db=database, **conn_kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/pymysql/__init__.py", line 88, in Connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: return Connection(*args, **kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 644, in __init__
Jun 12 10:23:54 www.example.com gunicorn[4763]: self._connect()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 823, in _connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: (self.host, self.port), self.connect_timeout)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/socket.py", line 570, in create_connection
Jun 12 10:23:54 www.example.com gunicorn[4763]: for res in getaddrinfo(host, port, 0 if has_ipv6 else AF_INET, SOCK_STREAM):
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/socket.py", line 621, in getaddrinfo
Jun 12 10:23:54 www.example.com gunicorn[4763]: return get_hub().resolver.getaddrinfo(host, port, family, socktype, proto, flags)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/resolver_thread.py", line 34, in getaddrinfo
Jun 12 10:23:54 www.example.com gunicorn[4763]: return self.pool.apply_e(self.expected_errors, _socket.getaddrinfo, args, kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 222, in apply_e
Jun 12 10:23:54 www.example.com gunicorn[4763]: success, result = self.spawn(wrap_errors, expected_errors, function, args, kwargs).get()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 159, in spawn
Jun 12 10:23:54 www.example.com gunicorn[4763]: self.adjust()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 133, in adjust
Jun 12 10:23:54 www.example.com gunicorn[4763]: self._adjust_step()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 113, in _adjust_step
Jun 12 10:23:54 www.example.com gunicorn[4763]: self._add_thread()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 142, in _add_thread
Jun 12 10:23:54 www.example.com gunicorn[4763]: start_new_thread(self._worker, ())
Jun 12 10:23:54 www.example.com gunicorn[4763]: error: can't start new thread
Jun 12 10:23:54 www.example.com gunicorn[4763]: [2015-06-12 10:23:54 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:55 www.example.com gunicorn[4763]: [2015-06-12 10:23:55 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:56 www.example.com gunicorn[4763]: [2015-06-12 10:23:56 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:57 www.example.com gunicorn[4763]: [2015-06-12 10:23:57 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:58 www.example.com gunicorn[4763]: [2015-06-12 10:23:58 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:59 www.example.com gunicorn[4763]: [2015-06-12 10:23:59 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:24:00 www.example.com gunicorn[4763]: [2015-06-12 10:24:00 +0000] [4763] [DEBUG] 3 workers
```

After some days this error raised. What is your view?
