-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage.py
executable file
·51 lines (37 loc) · 1.72 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env python
import sys
from SocketServer import BaseServer
from wsgiref import handlers
from tutorons.common.java.gateway import gateway
def patch_broken_pipe_error():
'''
This function helps us avoid a bunch of nasty error messages that
we don't want to see related to broekn pipes. Written with code reused from:
http://stackoverflow.com/questions/7912672/django-broken-pipe-in-debug-mode.
'''
handle_error_default = BaseServer.handle_error
log_exception_default = handlers.BaseHandler.log_exception
def is_error_from_broken_pipe():
type_, exception, traceback = sys.exc_info()
return exception is not None and "Broken pipe" in repr(exception)
def handle_error_patched(self, request, client_address):
if not is_error_from_broken_pipe():
handle_error_default(self, request, client_address)
def log_exception_patched(self, exc_info):
if not is_error_from_broken_pipe():
log_exception_default(self, exc_info)
BaseServer.handle_error = handle_error_patched
handlers.BaseHandler.log_exception = log_exception_patched
if __name__ == "__main__":
patch_broken_pipe_error()
from django.core.management import execute_from_command_line
try:
execute_from_command_line(sys.argv)
except:
# We make sure to catch all exceptions and raised events while running
# the main command. This includes keyboard interrupts.
# Because we are starting a gateway server to Java through Py4J, we still
# need to do the tear-down of shutting down the gateway once the main
# command has finished running, regardless of its outcome.
pass
gateway.shutdown(raise_exception=True)