Skip to content

Commit

Permalink
pywsgi: fix logging when bound on unix socket
Browse files Browse the repository at this point in the history
Thanks to Chris Meyers (gevent#295), Eugene Pankov (gevent#300).

Added examples: unixsocket_server.py and unixsocket_client.py that help reproduce the issue.
  • Loading branch information
denik committed Sep 14, 2013
1 parent aadb525 commit 82f5033
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/unixsocket_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import socket

s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("./unixsocket_server.py.sock")
s.send('GET / HTTP/1.0\r\n\r\n')
data = s.recv(1024)
print 'received %s bytes' % len(data)
print data
s.close()
18 changes: 18 additions & 0 deletions examples/unixsocket_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from gevent.pywsgi import WSGIServer
from gevent import socket


def application(environ, start_response):
start_response('200 OK', [])
return []


if __name__ == '__main__':
listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sockname = './' + os.path.basename(__file__) + '.sock'
if os.path.exists(sockname):
os.remove(sockname)
listener.bind(sockname)
listener.listen(1)
WSGIServer(listener, application).serve_forever()
3 changes: 2 additions & 1 deletion gevent/pywsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,9 @@ def format_request(self):
delta = '%.6f' % (self.time_finish - self.time_start)
else:
delta = '-'
client_address = self.client_address[0] if isinstance(self.client_address, tuple) else self.client_address
return '%s - - [%s] "%s" %s %s %s' % (
self.client_address[0],
client_address or '-',
now,
self.requestline,
(getattr(self, 'status', None) or '000').split()[0],
Expand Down
2 changes: 1 addition & 1 deletion greentest/test__examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


cwd = '../examples/'
ignore = ['wsgiserver.py', 'wsgiserver_ssl.py', 'webproxy.py', 'webpy.py']
ignore = ['wsgiserver.py', 'wsgiserver_ssl.py', 'webproxy.py', 'webpy.py', 'unixsocket_server.py', 'unixsocket_client.py']
if sys.platform == 'win32':
ignore += ['geventsendfile.py', 'psycopg2_pool.py']
ignore += [x[14:] for x in glob.glob('test__example_*.py')]
Expand Down

0 comments on commit 82f5033

Please sign in to comment.