本文整理匯總了Python中gevent.getcurrent方法的典型用法代碼示例。如果您正苦於以下問題:Python gevent.getcurrent方法的具體用法?Python gevent.getcurrent怎麽用?Python gevent.getcurrent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gevent
的用法示例。
在下文中一共展示了gevent.getcurrent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: kill
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def kill(self, block=False, reason="unknown"):
""" Forcefully kill all greenlets associated with this job """
current_greenletid = id(gevent.getcurrent())
trace = "Job killed: %s" % reason
for greenlet, job in context._GLOBAL_CONTEXT["greenlets"].values():
greenletid = id(greenlet)
if job and job.id == self.id and greenletid != current_greenletid:
greenlet.kill(block=block)
trace += "\n\n--- Greenlet %s ---\n" % greenletid
trace += "".join(traceback.format_stack(greenlet.gr_frame))
context._GLOBAL_CONTEXT["greenlets"].pop(greenletid, None)
if reason == "timeout" and self.data["status"] != "timeout":
updates = {
"exceptiontype": "TimeoutInterrupt",
"traceback": trace
}
self._save_status("timeout", updates=updates, exception=False)
示例2: _get_greenlet_scope
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def _get_greenlet_scope(self, greenlet=None):
if greenlet is None:
greenlet = gevent.getcurrent()
return getattr(greenlet, ACTIVE_ATTR, None)
示例3: _set_greenlet_scope
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def _set_greenlet_scope(self, scope, greenlet=None):
if greenlet is None:
greenlet = gevent.getcurrent()
setattr(greenlet, ACTIVE_ATTR, scope)
示例4: wrap_restore_handle_error
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def wrap_restore_handle_error(method):
@wraps(method)
def wrapped(self, *args, **kwargs):
old = gevent.get_hub().handle_error
try:
return method(self, *args, **kwargs)
finally:
gevent.get_hub().handle_error = old
if self.peek_error()[0] is not None:
gevent.getcurrent().throw(*self.peek_error()[1:])
return wrapped
示例5: work5
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def work5(num):
for i in range(num):
print("in work %s" % gevent.getcurrent())
time.sleep(0.3)
示例6: get_concurrent_info
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def get_concurrent_info(cls):
concurrent_info = ''
if cls.global_concurrent_mode == 1:
concurrent_info = f'[{threading.current_thread()} {threading.active_count()}]'
elif cls.global_concurrent_mode == 2:
concurrent_info = f'[{gevent.getcurrent()} {threading.active_count()}]'
elif cls.global_concurrent_mode == 3:
# noinspection PyArgumentList
concurrent_info = f'[{eventlet.getcurrent()} {threading.active_count()}]'
return concurrent_info
示例7: set_current_job
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def set_current_job(job):
current = gevent.getcurrent()
current.__dict__["_trace_time"] = 0
current.__dict__["_trace_switches"] = 0
if job is None:
if id(current) in _GLOBAL_CONTEXT["greenlets"]:
del _GLOBAL_CONTEXT["greenlets"][id(current)]
else:
_GLOBAL_CONTEXT["greenlets"][id(current)] = (current, job)
示例8: get_current_job
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def get_current_job(greenlet_id=None):
if greenlet_id is None:
greenlet_id = id(gevent.getcurrent())
pair = _GLOBAL_CONTEXT["greenlets"].get(greenlet_id)
if not pair:
return None
return pair[1]
示例9: run
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def run(self, params):
def get_clients():
return [c for c in connections.redis.client_list() if c.get("cmd") != "client"]
def inner(i):
print("Greenlet #%s, %s clients so far" % (id(gevent.getcurrent()), len(get_clients())))
return connections.redis.get("test")
if params["subpool_size"]:
subpool_map(params["subpool_size"], inner, list(range(0, params["subpool_size"] * 5)))
else:
inner(0)
示例10: filter
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def filter(self, record):
if record.pathname.startswith(self.__path_trim):
record.pathname = record.pathname[len(self.__path_trim):]
cur = gevent.getcurrent()
if cur == self._main_greenlet:
gname = 'gl-main'
else:
gname = getattr(cur, 'greenlet_name', str(cur))
record.greenlet = '{0!s}'.format(gname)
record.test_name = self.__current_test_name
record.test_case_number = self.__current_test_case_number
# This section removes the process, path, and greenlet information
# from any mssage that starts with any of the characters ' +-'.
# These are well known stream monitor messages and this informtion
# is not required to be displayed.
# TODO: there is probably a better way to do this but this will
# work until it is setup.
if any(elem in record.msg[0] for elem in r' +-?%'):
lif = ''
else:
u_lif = '{r.test_case_number} {r.process} {r.processName} {r.pathname}:{r.funcName}@{r.lineno} ' + \
'{r.greenlet} [{r.test_name}]'
lif = u_lif.format(r=record)
record.location_info_string = lif
return True
示例11: __init__
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def __init__(self, game_server_config, ports, server_handler_queue, launcher_queue):
gevent.getcurrent().name = 'gameserver'
self.servers = {}
self.server_handler_queue = server_handler_queue
self.launcher_queue = launcher_queue
self.logger = logging.getLogger(__name__)
self.ports = ports
try:
self.working_dir = game_server_config['dir']
self.dll_to_inject = game_server_config['controller_dll']
self.dll_config_path = game_server_config['controller_config']
except KeyError as e:
raise ConfigurationError("%s is a required configuration item under [gameserver]" % str(e))
self.exe_path = os.path.join(self.working_dir, 'TribesAscend.exe')
if not os.path.exists(self.working_dir):
raise ConfigurationError(
"Invalid 'dir' specified under [gameserver]: the directory does not exist")
if not os.path.exists(self.exe_path):
raise ConfigurationError(
"Invalid 'dir' specified under [gameserver]: the specified directory does not contain a TribesAscend.exe")
if not os.path.isabs(self.dll_to_inject):
self.dll_to_inject = os.path.abspath(self.dll_to_inject)
if not os.path.isabs(self.dll_config_path):
self.dll_config_path = os.path.abspath(self.dll_config_path)
self.logger.info(f'gameserver: path to controller DLL is {self.dll_to_inject}')
self.logger.info(f'gameserver: path to controller configuration is {self.dll_config_path}')
if not os.path.exists(self.dll_to_inject):
raise ConfigurationError(
"Invalid 'controller_dll' specified under [gameserver]: the specified file does not exist.")
if not os.path.exists(self.dll_config_path):
raise ConfigurationError(
"Invalid 'controller_config' specified under [gameserver]: the specified file does not exist")
示例12: handle_ping
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def handle_ping(ports):
gevent.getcurrent().name = 'pinghandler'
address = '0.0.0.0'
port = ports['launcherping']
try:
EchoServer('%s:%d' % (address, port)).serve_forever()
except OSError as e:
if e.errno == 10048:
raise PortInUseError('udp', address, port)
else:
raise
示例13: gevent_spawn
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def gevent_spawn(task_name: str, func, *args, **kwargs):
def wrapper_func(*args, **kwargs):
logger = logging.getLogger('gevent_spawn')
gevent.getcurrent().name = task_name
try:
return func(*args, **kwargs)
except Exception as e:
logger.exception('%s greenlet terminated with an unhandled exception:' % task_name, exc_info=e)
raise
return gevent.spawn(wrapper_func, *args, **kwargs)
示例14: gevent_spawn_later
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def gevent_spawn_later(task_name: str, seconds, func, *args, **kwargs):
def wrapper_func(*args, **kwargs):
logger = logging.getLogger('gevent_spawn_later')
gevent.getcurrent().name = task_name
try:
return func(*args, **kwargs)
except Exception as e:
logger.exception('%s greenlet terminated with an unhandled exception:' % task_name, exc_info=e)
raise
return gevent.spawn_later(seconds, wrapper_func, *args, **kwargs)
示例15: __init__
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import getcurrent [as 別名]
def __init__(self, config, incoming_queue):
gevent.getcurrent().name = 'authbot'
self.logger = logging.getLogger(__name__)
self.incoming_queue = incoming_queue
self.community_login_server = None
self.hirez_login_server = None
self.login_name = config['login_name']
self.display_name = None
self.password_hash = base64.b64decode(config['password_hash'])
self.last_requests = {}
self.smtp_server = config['smtp_server']
self.smtp_port = int(config['smtp_port'])
self.smtp_user = config['smtp_user']
self.smtp_password = config['smtp_password']
self.smtp_sender = config['smtp_sender']
self.smtp_usetls = config.getboolean('smtp_usetls')
self.message_handlers = {
PeerConnectedMessage: self.handle_peer_connected,
PeerDisconnectedMessage: self.handle_peer_disconnected,
Login2AuthAuthCodeResultMessage: self.handle_authcode_result_message,
Login2AuthChatMessage: self.handle_auth_channel_chat_message,
LoginProtocolMessage: self.handle_login_protocol_message,
}
address_pair, errormsg = IPAddressPair.detect()
if not address_pair.external_ip:
raise NoPublicIpAddressError(errormsg)
else:
self.logger.info('authbot: detected external IP: %s' % address_pair.external_ip)
self.login_server_address = address_pair.external_ip