Skip to content

Commit 14734c1

Browse files
committed
added experimantal branch
this branch is used for multiprocessing development
1 parent 8a3f6a0 commit 14734c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+29205
-0
lines changed

flask.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
from flask import Flask
2+
try:
3+
from PythonMiniProbe import probe
4+
except:
5+
import probe
6+
7+
import requests
8+
import json
9+
import gc
10+
import time
11+
import sys
12+
13+
pyprtg = Flask(__name__)
14+
15+
16+
@pyprtg.route('/')
17+
def mini_probe_home():
18+
return 'Python Mini Probe Home'
19+
20+
if __name__ == '__main__':
21+
pyprtg.debug = True
22+
pyprtg.run(host='0.0.0.0', port=50000)
23+
24+
# mini_probe = probe.Probe()
25+
# # Enable Garbage Collection
26+
# gc.enable()
27+
# # make sure the probe will not stop
28+
# probe_stop = False
29+
# # Create instance of Logger to provide logging
30+
# log = Logger()
31+
# # make sure probe is announced at every start
32+
# announce = False
33+
# # read configuration file (existence check done in probe_controller.py)
34+
# config = mini_probe.read_config('./probe.conf')
35+
# # create hash of probe access key
36+
# key_sha1 = mini_probe.hash_access_key(config['key'])
37+
# # get list of all sensors announced in __init__.py in package sensors
38+
# sensor_list = mini_probe.get_import_sensors()
39+
# sensor_announce = mini_probe.build_announce(sensor_list)
40+
# announce_json = json.dumps(sensor_announce)
41+
# url_announce = mini_probe.create_url(config, 'announce')
42+
# data_announce = mini_probe.create_parameters(config, announce_json, 'announce')
43+
#
44+
# while not announce:
45+
# try:
46+
# # announcing the probe and all sensors
47+
# request_announce = requests.get(url_announce, params=data_announce, verify=False)
48+
# announce = True
49+
# log.log(True, None, config, "ANNOUNCE", None, None)
50+
# if config['debug']:
51+
# log.log_custom(config['server'])
52+
# log.log_custom(config['port'])
53+
# log.log_custom("Status Code: %s | Message: %s" % (request_announce.status_code, request_announce.text))
54+
# request_announce.close()
55+
# except Exception as e:
56+
# log.log_custom(e)
57+
# time.sleep(int(config['baseinterval']) / 2)
58+
#
59+
# while not probe_stop:
60+
# # creating some objects only needed in loop
61+
# url_task = mini_probe.create_url(config, 'tasks')
62+
# task_data = {'gid':config['gid'], 'protocol':config['protocol'], 'key':key_sha1}
63+
#
64+
# task = False
65+
# while not task:
66+
# json_payload_data = []
67+
# try:
68+
# request_task = requests.get(url_task, params=task_data, verify=False)
69+
# json_response = request_task.json()
70+
# request_task.close()
71+
# gc.collect()
72+
# task = True
73+
# log.log(True, None, config, "TASK", None, None)
74+
# if config['debug']:
75+
# log.log_custom(url_task)
76+
# except Exception as e:
77+
# log.log_custom(e)
78+
# time.sleep(int(config['baseinterval']) / 2)
79+
# gc.collect()
80+
# if str(json_response) != '[]':
81+
# json_response_chunks = [json_response[i:i+10] for i in range(0, len(json_response), 10)]
82+
# for element in json_response_chunks:
83+
# for part in element:
84+
# if config['debug']:
85+
# log.log_custom(part)
86+
# for sensor in sensor_list:
87+
# if part['kind'] == sensor.get_kind():
88+
# json_payload_data.append(sensor.get_data(part))
89+
# else:
90+
# pass
91+
# gc.collect()
92+
# url_data = mini_probe.create_url(config, 'data')
93+
# try:
94+
# request_data = requests.post(url_data, data=json.dumps(json_payload_data), verify=False)
95+
# log.log(True, None, config, "DATA", None, None)
96+
#
97+
# if config['debug']:
98+
# log.log_custom(json_payload_data)
99+
# request_data.close()
100+
# json_payload_data = []
101+
# except Exception as e:
102+
# log.log_custom(e)
103+
# if (len(json_response) > 10):
104+
# time.sleep((int(config['baseinterval']) * (9 / len(json_response))))
105+
# else:
106+
# time.sleep(int(config['baseinterval']) / 2)
107+
# else:
108+
# log.log(True, "Nothing", config, None, None, None)
109+
# time.sleep(int(config['baseinterval']) / 3)
110+
#
111+
# # Delete some stuff used in the loop and run the garbage collector
112+
# del json_response
113+
# del json_payload_data
114+
# gc.collect()
115+
#
116+
# if config['cleanmem']:
117+
# # checking if the clean memory option has been chosen during install then call the method to flush mem
118+
# from utils import Utils
119+
# Utils.clean_mem()
120+
# sys.exit()
121+

flask/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
flask
4+
~~~~~
5+
6+
A microframework based on Werkzeug. It's extensively documented
7+
and follows best practice patterns.
8+
9+
:copyright: (c) 2014 by Armin Ronacher.
10+
:license: BSD, see LICENSE for more details.
11+
"""
12+
13+
__version__ = '0.11-dev'
14+
15+
# utilities we import from Werkzeug and Jinja2 that are unused
16+
# in the module but are exported as public interface.
17+
from werkzeug.exceptions import abort
18+
from werkzeug.utils import redirect
19+
from jinja2 import Markup, escape
20+
21+
from .app import Flask, Request, Response
22+
from .config import Config
23+
from .helpers import url_for, flash, send_file, send_from_directory, \
24+
get_flashed_messages, get_template_attribute, make_response, safe_join, \
25+
stream_with_context
26+
from .globals import current_app, g, request, session, _request_ctx_stack, \
27+
_app_ctx_stack
28+
from .ctx import has_request_context, has_app_context, \
29+
after_this_request, copy_current_request_context
30+
from .module import Module
31+
from .blueprints import Blueprint
32+
from .templating import render_template, render_template_string
33+
34+
# the signals
35+
from .signals import signals_available, template_rendered, request_started, \
36+
request_finished, got_request_exception, request_tearing_down, \
37+
appcontext_tearing_down, appcontext_pushed, \
38+
appcontext_popped, message_flashed
39+
40+
# We're not exposing the actual json module but a convenient wrapper around
41+
# it.
42+
from . import json
43+
44+
# This was the only thing that flask used to export at one point and it had
45+
# a more generic name.
46+
jsonify = json.jsonify
47+
48+
# backwards compat, goes away in 1.0
49+
from .sessions import SecureCookieSession as Session
50+
json_available = True

flask/__main__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
flask.__main__
4+
~~~~~~~~~~~~~~
5+
6+
Alias for flask.run for the command line.
7+
8+
:copyright: (c) 2014 by Armin Ronacher.
9+
:license: BSD, see LICENSE for more details.
10+
"""
11+
12+
13+
if __name__ == '__main__':
14+
from .cli import main
15+
main(as_module=True)

flask/_compat.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
flask._compat
4+
~~~~~~~~~~~~~
5+
6+
Some py2/py3 compatibility support based on a stripped down
7+
version of six so we don't have to depend on a specific version
8+
of it.
9+
10+
:copyright: (c) 2014 by Armin Ronacher.
11+
:license: BSD, see LICENSE for more details.
12+
"""
13+
import sys
14+
15+
PY2 = sys.version_info[0] == 2
16+
_identity = lambda x: x
17+
18+
19+
if not PY2:
20+
text_type = str
21+
string_types = (str,)
22+
integer_types = (int,)
23+
24+
iterkeys = lambda d: iter(d.keys())
25+
itervalues = lambda d: iter(d.values())
26+
iteritems = lambda d: iter(d.items())
27+
28+
from io import StringIO
29+
30+
def reraise(tp, value, tb=None):
31+
if value.__traceback__ is not tb:
32+
raise value.with_traceback(tb)
33+
raise value
34+
35+
implements_to_string = _identity
36+
37+
else:
38+
text_type = unicode
39+
string_types = (str, unicode)
40+
integer_types = (int, long)
41+
42+
iterkeys = lambda d: d.iterkeys()
43+
itervalues = lambda d: d.itervalues()
44+
iteritems = lambda d: d.iteritems()
45+
46+
from cStringIO import StringIO
47+
48+
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')
49+
50+
def implements_to_string(cls):
51+
cls.__unicode__ = cls.__str__
52+
cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
53+
return cls
54+
55+
56+
def with_metaclass(meta, *bases):
57+
# This requires a bit of explanation: the basic idea is to make a
58+
# dummy metaclass for one level of class instantiation that replaces
59+
# itself with the actual metaclass. Because of internal type checks
60+
# we also need to make sure that we downgrade the custom metaclass
61+
# for one level to something closer to type (that's why __call__ and
62+
# __init__ comes back from type etc.).
63+
#
64+
# This has the advantage over six.with_metaclass in that it does not
65+
# introduce dummy classes into the final MRO.
66+
class metaclass(meta):
67+
__call__ = type.__call__
68+
__init__ = type.__init__
69+
def __new__(cls, name, this_bases, d):
70+
if this_bases is None:
71+
return type.__new__(cls, name, (), d)
72+
return meta(name, bases, d)
73+
return metaclass('temporary_class', None, {})
74+
75+
76+
# Certain versions of pypy have a bug where clearing the exception stack
77+
# breaks the __exit__ function in a very peculiar way. This is currently
78+
# true for pypy 2.2.1 for instance. The second level of exception blocks
79+
# is necessary because pypy seems to forget to check if an exception
80+
# happened until the next bytecode instruction?
81+
BROKEN_PYPY_CTXMGR_EXIT = False
82+
if hasattr(sys, 'pypy_version_info'):
83+
class _Mgr(object):
84+
def __enter__(self):
85+
return self
86+
def __exit__(self, *args):
87+
sys.exc_clear()
88+
try:
89+
try:
90+
with _Mgr():
91+
raise AssertionError()
92+
except:
93+
raise
94+
except TypeError:
95+
BROKEN_PYPY_CTXMGR_EXIT = True
96+
except AssertionError:
97+
pass

0 commit comments

Comments
 (0)