From 095f9b3bc9a716fbac12fd27fa93b33c342815b5 Mon Sep 17 00:00:00 2001 From: Nyo Date: Tue, 23 Aug 2016 20:16:47 +0200 Subject: [PATCH] .BANCHO. Switched to tornado+gevent --- README.md | 7 ++++--- constants/fokabotCommands.py | 1 - helpers/configHelper.py | 2 -- helpers/requestHelper.py | 7 +++++-- objects/glob.py | 1 - pep.py | 12 ++---------- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index aeff15c..a9f04a8 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ This is Ripple's bancho server. It handles: ## Requirements - Python 3.5 - MySQLdb (`mysqlclient` or `mysql-python`) -- Tornado (`tornado`) -- Bcrypt (`bcrypt`) +- Tornado +- Gevent +- Bcrypt ## How to set up pep.py First of all, install all the dependencies ``` -$ pip install mysqlclient tornado bcrypt +$ pip install mysqlclient tornado gevent bcrypt ``` then, run pep.py once to create the default config file and edit it ``` diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 3d14cb0..1390c37 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -586,7 +586,6 @@ def tillerinoLast(fro, chan, message): stars = oppaiData["stars"] msg += " | {0:.2f} stars".format(stars) - return msg except Exception as a: log.error(a) diff --git a/helpers/configHelper.py b/helpers/configHelper.py index 4953075..7db920b 100644 --- a/helpers/configHelper.py +++ b/helpers/configHelper.py @@ -49,7 +49,6 @@ class config: self.config.get("db","workers") self.config.get("server","port") - self.config.get("server","threads") self.config.get("server","gzip") self.config.get("server","gziplevel") self.config.get("server","cikey") @@ -94,7 +93,6 @@ class config: self.config.add_section("server") self.config.set("server", "port", "5001") - self.config.set("server", "threads", "16") self.config.set("server", "gzip", "1") self.config.set("server", "gziplevel", "6") self.config.set("server", "cikey", "changeme") diff --git a/helpers/requestHelper.py b/helpers/requestHelper.py index 0599180..f397ce3 100644 --- a/helpers/requestHelper.py +++ b/helpers/requestHelper.py @@ -5,6 +5,7 @@ from tornado.ioloop import IOLoop from objects import glob from raven.contrib.tornado import SentryMixin from raven.contrib.tornado import AsyncSentryClient +import gevent class asyncRequestHandler(tornado.web.RequestHandler): """ @@ -58,8 +59,10 @@ def runBackground(data, callback): func, args, kwargs = data def _callback(result): IOLoop.instance().add_callback(lambda: callback(result)) - glob.pool.apply_async(func, args, kwargs, _callback) - + #glob.pool.apply_async(func, args, kwargs, _callback) + g = gevent.Greenlet(func, *args, **kwargs) + g.link(_callback) + g.start() def checkArguments(arguments, requiredArguments): """ diff --git a/objects/glob.py b/objects/glob.py index 9aac829..4182d26 100644 --- a/objects/glob.py +++ b/objects/glob.py @@ -20,7 +20,6 @@ tokens = tokenList.tokenList() channels = channelList.channelList() matches = matchList.matchList() restarting = False -pool = None fLocks = fileLocks.fileLocks() verifiedCache = {} cloudflare = False diff --git a/pep.py b/pep.py index 236a07e..16854bd 100644 --- a/pep.py +++ b/pep.py @@ -1,7 +1,6 @@ """Hello, pep.py here, ex-owner of ripple and prime minister of Ripwot.""" import sys import os -from multiprocessing.pool import ThreadPool import threading # Tornado @@ -9,6 +8,8 @@ import tornado.ioloop import tornado.web import tornado.httpserver import tornado.gen +from gevent import monkey as brit_monkey +brit_monkey.patch_all() # Raven from raven.contrib.tornado import AsyncSentryClient @@ -98,15 +99,6 @@ if __name__ == "__main__": glob.tokens.deleteBanchoSessions() consoleHelper.printDone() - # Create threads pool - try: - consoleHelper.printNoNl("> Creating threads pool... ") - glob.pool = ThreadPool(int(glob.conf.config["server"]["threads"])) - consoleHelper.printDone() - except: - consoleHelper.printError() - consoleHelper.printColored("[!] Error while creating threads pool. Please check your config.ini and run the server again", bcolors.RED) - try: consoleHelper.printNoNl("> Loading chat filters... ") glob.chatFilters = chatFilters.chatFilters()