-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbootstrap.py
54 lines (47 loc) · 1.69 KB
/
bootstrap.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
52
53
54
import config
import logging
import time
from raven.handlers.logging import SentryHandler
from raven.conf import setup_logging
logging.getLogger().setLevel(config.loglevel)
installed = ["irc", "manager", "requests_", "afkstreamer"]
if __name__ == "__main__":
for module in installed:
try:
__import__(module).launch_server()
except:
logging.exception("Fucking loading broke, FIX YOUR SHIT")
def logging_setup():
root = logging.getLogger()
root.setLevel(config.loglevel)
client = SentryHandler(config.sentry_key)
setup_logging(client)
def stats():
"""Returns information about the process"""
from threading import active_count, enumerate
try:
threads = active_count()
names = [(thread.name, hex(id(thread))) for thread in enumerate()]
except:
threads = 0
names = []
return (names, threads)
class Singleton(type):
def __init__(mcs, name, bases, dict):
super(Singleton, mcs).__init__(name, bases, dict)
mcs.instance = None
def __call__(mcs, *args, **kw):
if mcs.instance is None:
mcs.instance = super(Singleton, mcs).__call__(*args, **kw)
return mcs.instance
class Switch(object):
def __init__(self, initial, timeout=15):
object.__init__(self)
self.state = initial
self.timeout = time.time() + timeout
def __nonzero__(self):
return False if self.timeout <= time.time() else self.state
def __bool__(self):
return False if self.timeout <= time.time() else self.state
def reset(self, timeout=15):
self.timeout = time.time() + timeout