source: src/media_conv/__init__.py @ 4698

Last change on this file since 4698 was 4698, checked in by Sander.Maijers@mpi.nl, 10 years ago

Horizontal showcase WebMAUS:
media_conv component

Documentation: https://trac.clarin.eu/media_conv

As deployed on: http://infra.clarin.eu/app/media_conv

File size: 1.2 KB
Line 
1# -*- coding: utf-8 -*-
2
3__all__ = ["cache", "connectivity", "conversion", "tests", "views"]
4
5import logging
6
7logger = logging.getLogger('waitress')
8
9from resource import setrlimit, RLIMIT_NPROC
10
11from getpass import getuser
12
13unix_username = getuser()
14
15import pprint
16import resource
17
18try:
19    from pyramid.config import Configurator
20    from pyramid.settings import asbool
21
22    def main(global_config,
23             **settings):
24
25        try:
26            settings['max_n_threads'] = int(settings['max_n_threads'])
27            settings['caching'] = asbool(settings['caching'])
28        except (KeyError, TypeError, ValueError) as e:
29            logger.error("Waitress configuration error. " + pprint.pformat(e))
30        else:
31
32            setrlimit(RLIMIT_NPROC, (settings['max_n_threads'], settings['max_n_threads']))
33
34            config = Configurator(settings=settings)
35
36            config.add_route("media_conv",
37                             "/media_conv")
38
39            config.scan()
40
41            return config.make_wsgi_app()
42except BlockingIOError as e:
43    logger.critical("System resource limit for RLIMIT_NPROC (set to {0}) is being exceeded for current user '{1}'! {2}"
44        .format(resource.getrlimit(RLIMIT_NPROC), unix_username, pprint.pformat(e)))
45    raise
Note: See TracBrowser for help on using the repository browser.