コード例 #1
0
ファイル: lock.py プロジェクト: wellbehavedsoftware/gevent
class RLock(object):

    def __init__(self):
        self._block = Semaphore(1)
        self._owner = None
        self._count = 0

    def __repr__(self):
        return "<%s at 0x%x _block=%s _count=%r _owner=%r)>" % (
            self.__class__.__name__,
            id(self),
            self._block,
            self._count,
            self._owner)

    def acquire(self, blocking=1):
        me = getcurrent()
        if self._owner is me:
            self._count = self._count + 1
            return 1
        rc = self._block.acquire(blocking)
        if rc:
            self._owner = me
            self._count = 1
        return rc

    def __enter__(self):
        return self.acquire()

    def release(self):
        if self._owner is not getcurrent():
            raise RuntimeError("cannot release un-aquired lock")
        self._count = count = self._count - 1
        if not count:
            self._owner = None
            self._block.release()

    def __exit__(self, typ, value, tb):
        self.release()

    # Internal methods used by condition variables

    def _acquire_restore(self, count_owner):
        count, owner = count_owner
        self._block.acquire()
        self._count = count
        self._owner = owner

    def _release_save(self):
        count = self._count
        self._count = 0
        owner = self._owner
        self._owner = None
        self._block.release()
        return (count, owner)

    def _is_owned(self):
        return self._owner is getcurrent()
コード例 #2
0
import random, time, json
import base64
import sys
import queue
from requests_toolbelt import MultipartEncoder
sys.path.append("F:/myTestFile/TestObject/TongChuangYuanMa")
from yunqianbao.qianMing import GetDataSign
from yunqianbao.publicRequestMethod import PublicRequest
from common.writeAndReadText import WriteAndReadTextFile
from yunqianbao.single.publicData import PublicDataClass
from yunqianbao.single.userMobile import user_mobile
from yunqianbao.pengyou.pengYouClass import PengYouClass
from common.userAgent import UserAgent
from gevent._semaphore import Semaphore
all_locusts_spawned = Semaphore()  #计数器
all_locusts_spawned.acquire()  #计数器为0时阻塞线程 每当调用acquire()时,内置计数器-1


def on_hatch_complete(**kwargs):
    all_locusts_spawned.release()  #内置计数器+1


events.hatch_complete += on_hatch_complete


class YunQianBaoMan(TaskSet):
    def on_start(self):
        self.header = {
            "Connection": "keep-alive",
            "app-type": "android",  #android
            "mobile-unid": str(int(round(time.time() * 100000))),
コード例 #3
0
from bin.Yaml import get_env
from locust import events, TaskSet, task, HttpLocust
from gevent._semaphore import Semaphore

all_locusts_spawned = Semaphore()
all_locusts_spawned.acquire()


def on_hatch_complete(**kwargs):
    all_locusts_spawned.release()


events.hatch_complete += on_hatch_complete
env = get_env()
headers = {
    "User-Agent":
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko)\
                                  Chrome/67.0.3396.99 Safari/537.36",
    "Content-Type": "application/x-www-form-urlencoded",
    # "Connection": "close"
}


class TestTask(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled
            所有压测的task执行之前等待登录完成
        """
        self.console_host = 'https://iam-test.ctcdn.cn'
        self.workspace_id = "10003885"
        self.login()
コード例 #4
0
from locust import HttpUser,task,TaskSet,between,events
import time,json,random,sys,queue
<<<<<<< HEAD
sys.path.append("E:/myTestFile/TestObject/TongChuangYuanMa")
=======
sys.path.append("F:/myTestFile/TestObject/TongChuangYuanMa")
>>>>>>> cab62fe0f6e06f77d99222bd0a09668caebc2748
from Interface.QueryUsers import queryUsers_ykf
from test_script.publicscript.publicRequestMethod import PublicRequest
from yunkufang.ykf_login import UserLogin
from yunkufang.chuangXinShiChang import ChuangXinShiChang
from gevent._semaphore import Semaphore
from yunqianbao.single.userMobile import user_mobile
spawned = Semaphore() #计数器
spawned.acquire() #计数器为0时阻塞线程 每当调用acquire()时,内置计数器-1
def on_hatch_complete(**kwargs):
    spawned.release() #内置计数器+1
    # print(spawned.release())

# events.spawning_complete += on_hatch_complete
# events.hatch_complete += on_hatch_complete

class CXSCLiuCheng(TaskSet):
    def on_start(self):
        self.header = {
            "User-Agent":"Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; ALP-TL00 Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 YunKuFang/1.3.3",
            "mobile-system":"android8.0.0",
            "app-type":"Android",
            "app-version":"1.3.3",
            "app-version-code":"13",
            "mobile-unid":"866215038845167",
コード例 #5
0
class RLock(object):
    """
    A mutex that can be acquired more than once by the same greenlet.

    A mutex can only be locked by one greenlet at a time. A single greenlet
    can `acquire` the mutex as many times as desired, though. Each call to
    `acquire` must be paired with a matching call to `release`.

    It is an error for a greenlet that has not acquired the mutex
    to release it.

    Instances are context managers.
    """

    __slots__ = (
        '_block',
        '_owner',
        '_count',
        '__weakref__',
    )

    def __init__(self, hub=None):
        """
        .. versionchanged:: 20.5.1
           Add the ``hub`` argument.
        """
        self._block = Semaphore(1, hub)
        self._owner = None
        self._count = 0

    def __repr__(self):
        return "<%s at 0x%x _block=%s _count=%r _owner=%r)>" % (
            self.__class__.__name__, id(self), self._block, self._count,
            self._owner)

    def acquire(self, blocking=True, timeout=None):
        """
        Acquire the mutex, blocking if *blocking* is true, for up to
        *timeout* seconds.

        .. versionchanged:: 1.5a4
           Added the *timeout* parameter.

        :return: A boolean indicating whether the mutex was acquired.
        """
        me = getcurrent()
        if self._owner is me:
            self._count = self._count + 1
            return 1
        rc = self._block.acquire(blocking, timeout)
        if rc:
            self._owner = me
            self._count = 1
        return rc

    def __enter__(self):
        return self.acquire()

    def release(self):
        """
        Release the mutex.

        Only the greenlet that originally acquired the mutex can
        release it.
        """
        if self._owner is not getcurrent():
            raise RuntimeError("cannot release un-acquired lock")
        self._count = count = self._count - 1
        if not count:
            self._owner = None
            self._block.release()

    def __exit__(self, typ, value, tb):
        self.release()

    # Internal methods used by condition variables

    def _acquire_restore(self, count_owner):
        count, owner = count_owner
        self._block.acquire()
        self._count = count
        self._owner = owner

    def _release_save(self):
        count = self._count
        self._count = 0
        owner = self._owner
        self._owner = None
        self._block.release()
        return (count, owner)

    def _is_owned(self):
        return self._owner is getcurrent()
コード例 #6
0
import random, time, json
import base64
import sys
import queue
# from multiprocessing import Queue
from requests_toolbelt import MultipartEncoder

sys.path.append("E:/myTestFile/TestObject/zhongfuan/yunkufang/ykf_pressure")
from case.class_api_test import ZFAclassTestCase
from case.qianMing import GetDataSign
from common.userMobile import user_mobile
from common.userAgent import UserAgent
from gevent._semaphore import Semaphore

all_locusts_spawned = Semaphore()
all_locusts_spawned.acquire()  #减1


def on_spawning_complete(**kwargs):
    all_locusts_spawned.release()  #创建钩子方法


events.spawning_complete.add_listener(
    on_spawning_complete)  #挂载到locust钩子函数(所有的Locust实例产生完成时触发)


class YunQianBaoMan(TaskSet):
    def on_start(self):
        self.headers = {
            "Connection":
            "keep-alive",