def init(self): import options from UnityEngine import Debug L = lambda s: Debug.Log("PyWrap: " + s) L("init") self.events = [] # should set them options.no_update options.show_hidden_mode options.freeplay = False if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate L("before gevent") from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() L("after gevent") from game import autoenv autoenv.init('Client') import thb.ui.ui_meta # noqa, init ui_meta from client.core.executive import Executive self.executive = ExecutiveWrapper(Executive, self)
def monkeypatch_runner(): # monkey patch for greenlet support # monkey.patch_all() - raising key error in Py 2.7.9 monkey.patch_socket() monkey.patch_dns() monkey.patch_ssl() monkey.patch_os()
def start(self): super(WSGIServer, self).start() if self.fork > 1: from gevent.monkey import patch_os patch_os() for i in range(self.fork): pid = os.fork() if pid < 0: # pragma: no cover sys.exit('Failed to fork worker %s', i) if pid == 0: return # pragma: no cover self.workers.append(pid)
def init(self): import options from UnityEngine import Debug L = lambda s: Debug.Log("PyWrap: " + s) L("init") self.events = [] # should set them options.no_update options.no_crashreport options.show_hidden_mode options.freeplay = False if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate L("before gevent") from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() L("after gevent") from game import autoenv autoenv.init('Client') import gamepack.thb.ui.ui_meta # noqa, init ui_meta # For debug @gevent.spawn def beat(): while True: gevent.sleep(1) # self.events.append(("tick",)) from client.core.executive import Executive self.executive = ExecutiveWrapper(Executive, self)
def start(self): from multiprocessing import Process from gevent import monkey monkey.patch_socket() monkey.patch_os() from gevent.wsgi import WSGIServer server = WSGIServer((self.host, self.port), self.handler) server.pre_start() def serve_forever(): logger.info('starting server') try: server.start_accepting() try: server._stopped_event.wait() except: raise except KeyboardInterrupt: pass for i in range(2): Process(target=serve_forever, args=tuple()).start() serve_forever()
from gevent import monkey from gevent import socket monkey.patch_os() monkey.patch_socket() monkey.patch_ssl() import time import gogo_cfg cfg = gogo_cfg.gogo_cfg() timelimit = float(cfg.get("Socket", "timeout")) loop = float(cfg.get("Socket", "loop")) def Socket_Test(IP, Port = 443): STA = time.time() #============== #print "Start", IP try: for i in range(int(loop)): s = socket.socket() s.settimeout(timelimit) s.connect((IP, Port)) s.close() cost = time.time()-STA return True ,IP , cost/loop except socket.error: #raise s.close() return False, IP , 65536 #finally: #print "End", IP if __name__ == "__main__":
#coding:utf8 from gevent import monkey; monkey.patch_os() if __name__=="__main__": from gfirefly.master.master import Master master = Master() master.config('config.json','appmain.py') master.start()
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import utils.logging parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', action='store_true') parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--show-hidden-modes', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') import settings utils.logging.init(options.log.upper(), settings.SENTRY_DSN, IS_PROTON or options.color_log) utils.logging.patch_gevent_hub_print_exception() if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate log = logging.getLogger('start_client') from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game atexit.register(game.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() log.exception(u'UI线程崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) raise
# -*- coding: utf-8 -*- """ Copyright (C) 2019, Zato Source s.r.o. https://zato.io Licensed under LGPLv3, see LICENSE.txt for terms and conditions. """ from __future__ import absolute_import, division, print_function, unicode_literals # Monkey-patching modules individually can be about 20% faster, # or, in absolute terms, instead of 275 ms it may take 220 ms. from gevent.monkey import patch_builtins, patch_contextvars, patch_thread, patch_time, patch_os, patch_queue, patch_select, \ patch_selectors, patch_signal, patch_socket, patch_ssl, patch_subprocess, patch_sys # Note that the order of patching matters, just like in patch_all patch_os() patch_time() patch_thread() patch_sys() patch_socket() patch_select() patch_selectors() patch_ssl() patch_subprocess() patch_builtins() patch_signal() patch_queue() patch_contextvars() # stdlib import locale
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import crashreport parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', action='store_true') parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--no-crashreport', action='store_true') parser.add_argument('--show-hidden-modes', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') crashreport.install_tee(options.log.upper()) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate if IS_PROTON or options.color_log: from colorlog import ColoredFormatter formatter = ColoredFormatter("%(log_color)s%(message)s%(reset)s", log_colors={ 'CRITICAL': 'bold_red', 'ERROR': 'red', 'WARNING': 'yellow', 'INFO': 'green', 'DEBUG': 'blue', }) logging.getLogger().handlers[0].setFormatter(formatter) log = logging.getLogger('start_client') from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game atexit.register(game.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() if not options.no_crashreport: log.error(u'游戏崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) from crashreport import do_crashreport do_crashreport() raise
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import utils.logging parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', type=int, default=None) parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--zoom', type=float, default=1.0) parser.add_argument('--show-hidden-modes', action='store_true') parser.add_argument('--multiple-instances', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') import settings utils.logging.init(options.log.upper(), settings.SENTRY_DSN, settings.VERSION, IS_PROTON or options.color_log) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate log = logging.getLogger('start_client') if sys.platform.startswith('win32') and not options.multiple_instances: from utils.mutex import NamedMutex thb_mutex = NamedMutex('thbattle-mutex') if not thb_mutex.acquire(0): log.error('Multiple instances detected, exiting') ctypes.windll.user32.MessageBoxW( 0, u'请遵守社区规范,素质游戏,不要开启多个游戏实例!', u'东方符斗祭', 16, ) sys.exit(0) opmodule.mutex = thb_mutex else: opmodule.mutex = None from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game.base atexit.register(game.base.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.base.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui # PIL compat from PIL import Image try: Image.frombytes Image.Image.tobytes except AttributeError: log.info('Patching PIL {from,to}bytes') Image.frombytes = Image.fromstring Image.Image.tobytes = Image.Image.tostring # ---------- try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() log.exception(u'UI线程崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) raise
# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. from __future__ import with_statement, absolute_import from gevent.monkey import patch_os patch_os() import os import sys import errno import logging from signal import SIGHUP, SIGKILL, SIGQUIT, SIGINT, SIGTERM import atexit from zope.interface import implements from gevent import sleep, spawn, socket, signal, version_info from gevent.server import StreamServer from gevent.event import Event try: from gevent.lock import Semaphore
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import utils.logging parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', type=int, default=None) parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--zoom', type=float, default=1.0) parser.add_argument('--show-hidden-modes', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') import settings utils.logging.init(options.log.upper(), settings.SENTRY_DSN, settings.VERSION, IS_PROTON or options.color_log) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate log = logging.getLogger('start_client') from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game.base atexit.register(game.base.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.base.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui # PIL compat from PIL import Image try: Image.frombytes Image.Image.tobytes except AttributeError: log.info('Patching PIL {from,to}bytes') Image.frombytes = Image.fromstring Image.Image.tobytes = Image.Image.tostring # ---------- try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() log.exception(u'UI线程崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) raise
from exchange.bittrex import Bittrex from exchange.data_proxy import DataProxy import datetime import dateutil.parser import time import pandas as pd import gevent from gevent import monkey monkey.patch_time() monkey.patch_socket() monkey.patch_signal() monkey.patch_os() monkey.patch_dns() monkey.patch_sys() from exchange.data_proxy import DataProxy SPREAD_THRESHOLD = 0.1 def on_tick(pair, exchange): my_sell_order = 0 my_buy_order = 0 # run in loop outside 3s/tick data_api = DataProxy(exchange) order_slice = data_api.order_books(pair, 100)['result']
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import crashreport parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument("--no-update", action="store_true") parser.add_argument("--with-gl-errcheck", action="store_true") parser.add_argument("--freeplay", action="store_true") parser.add_argument("--fastjoin", action="store_true") parser.add_argument("--dump-gameobj", action="store_true") parser.add_argument("--log", default="INFO") parser.add_argument("--color-log", action="store_true") parser.add_argument("--no-crashreport", action="store_true") parser.add_argument("--show-hidden-modes", action="store_true") options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, "uname") and os.uname()[:2] == ("Linux", "Proton") crashreport.install_tee(options.log.upper()) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate if IS_PROTON or options.color_log: from colorlog import ColoredFormatter formatter = ColoredFormatter( "%(log_color)s%(message)s%(reset)s", log_colors={"CRITICAL": "bold_red", "ERROR": "red", "WARNING": "yellow", "INFO": "green", "DEBUG": "blue"}, ) logging.getLogger().handlers[0].setFormatter(formatter) log = logging.getLogger("start_client") from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init("Client") import pyglet pyglet.options["shadow_window"] = False if not options.with_gl_errcheck: pyglet.options["debug_gl"] = False from pyglet.gl import gl_info if gl_info.get_renderer() == "GDI Generic": ctypes.windll.user32.MessageBoxW(0, u"你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!", u"需要显卡驱动", 16) sys.exit(0) if sys.platform.startswith("linux") and options.dump_gameobj: import atexit import game atexit.register(game.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() if not options.no_crashreport: log.error(u"游戏崩溃,正在报告bug,请稍等下……") from utils.stats import stats stats({"event": "crash"}) from crashreport import do_crashreport do_crashreport() raise