Skip to content

Commit

Permalink
Fix memory exhaustion error when calling fork().
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-osman committed Aug 29, 2016
1 parent 2077b8c commit fd1155e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions twobuntu/views.py
Expand Up @@ -35,28 +35,39 @@ def index(request):
})


def about(request):
def commit():
"""
Render the about page.
Retrieve the current commit.
"""
try:
process = Popen(['git', 'log', '-1'], stdout=PIPE, cwd=path.dirname(__file__))
output, error = process.communicate()
commit = {
return {
'hash': search(br'commit\s*(.*)', output).group(1)[:8],
'author': search(br'Author:\s*(.*)<', output).group(1),
'date': parse(search(br'Date:\s*(.*)', output).group(1)),
}
except (AttributeError, CalledProcessError):
commit = {}
return {}


# Due to memory problems with fork, the git commit information should be
# retrieved only once when the application starts
_commit = commit()


def about(request):
"""
Render the about page.
"""
return render(request, 'pages/about.html', {
'title': 'About Us',
'num_articles': Article.objects.filter(status=Article.PUBLISHED).count(),
'num_users': User.objects.filter(is_active=True).count(),
'hostname': gethostname(),
'django_version': get_version(),
'python_version': python_version(),
'commit': commit,
'commit': _commit,
})


Expand Down

0 comments on commit fd1155e

Please sign in to comment.