Best Python code snippet using locust
thread.py
Source:thread.py  
...62        self.release()63_threads = {}64_nextThreadId = 065_threadsLock = pm.Mutex('thread._threadsLock')66def start_new_thread(function, args, kwargs = {}, name = None):67    def threadFunc(threadId, function = function, args = args, kwargs = kwargs):68        try:69            try:70                function(*args, **kwargs)71            except SystemExit:72                pass73        finally:74            _remove_thread_id(threadId)75    global _nextThreadId76    _threadsLock.acquire()77    try:78        threadId = _nextThreadId79        _nextThreadId += 180        if name is None:81            name = 'PythonThread-%s' % (threadId)82            83        thread = pm.PythonThread(threadFunc, [threadId], name, name)84        thread.setPythonData(threadId)85        _threads[threadId] = (thread, {}, None)86        87        thread.start(pm.TPNormal, False)88        return threadId89    finally:90        _threadsLock.release()91def _add_thread(thread, wrapper):92    """ Adds the indicated pm.Thread object, with the indicated Python93    wrapper, to the thread list.  Returns the new thread ID. """94    95    global _nextThreadId96    _threadsLock.acquire()97    try:98        threadId = _nextThreadId99        _nextThreadId += 1100            101        thread.setPythonData(threadId)102        _threads[threadId] = (thread, {}, wrapper)103        return threadId104        105    finally:...threads.py
Source:threads.py  
...3from api.tools import DBconnect4"""5Helper class to manipulate with thread.6"""7def save_thread(forum, title, isClosed, user, date, message, slug, optional):8    DBconnect.exist(entity="user", identifier="email", value=user)9    DBconnect.exist(entity="forum", identifier="short_name", value=forum)10    isDeleted = 011    if "isDeleted" in optional:12        isDeleted = optional["isDeleted"]13    thread = DBconnect.select_query(14        'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '15        'FROM thread WHERE slug = %s', (slug, )16    )17    if len(thread) == 0:18        DBconnect.update_query('INSERT INTO thread (forum, title, isClosed, user, date, message, slug, isDeleted) '19                               'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',20                               (forum, title, isClosed, user, date, message, slug, isDeleted, ))21        thread = DBconnect.select_query(22            'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '23            'FROM thread WHERE slug = %s', (slug, )24        )25    thread = thread[0]26    response = {27        'date': str(thread[0]),28        'forum': thread[1],29        'id': thread[2],30        'isClosed': bool(thread[3]),31        'isDeleted': bool(thread[4]),32        'message': thread[5],33        'slug': thread[6],34        'title': thread[7],35        'user': thread[8],36        'dislikes': thread[9],37        'likes': thread[10],38        'points': thread[11],39        'posts': thread[12],40    }41    # Delete few extra elements42    del response["dislikes"]43    del response["likes"]44    del response["points"]45    del response["posts"]46    return response47def details(id, related):48    thread = DBconnect.select_query(49        'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '50        'FROM thread WHERE id = %s LIMIT 1;', (id, )51    )52    if len(thread) == 0:53        raise Exception('No thread exists with id=' + str(id))54    thread = thread[0]55    thread = {56        'date': str(thread[0]),57        'forum': thread[1],58        'id': thread[2],59        'isClosed': bool(thread[3]),60        'isDeleted': bool(thread[4]),61        'message': thread[5],62        'slug': thread[6],63        'title': thread[7],64        'user': thread[8],65        'dislikes': thread[9],66        'likes': thread[10],67        'points': thread[11],68        'posts': thread[12],69    }70    if "user" in related:71        thread["user"] = users.details(thread["user"])72    if "forum" in related:73        thread["forum"] = forums.details(short_name=thread["forum"], related=[])74    return thread75def details_in(in_str):76    query = "SELECT date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts FROM thread" \77            " WHERE id IN (%s);"78    print(query % (in_str, ))79    threads = DBconnect.select_query(query, (in_str, ))80    print(in_str)81    print(threads)82    thread_list = {}83    for thread in threads:84        thread = {85            'date': str(thread[0]),86            'forum': thread[1],87            'id': thread[2],88            'isClosed': bool(thread[3]),89            'isDeleted': bool(thread[4]),90            'message': thread[5],91            'slug': thread[6],92            'title': thread[7],93            'user': thread[8],94            'dislikes': thread[9],95            'likes': thread[10],96            'points': thread[11],97            'posts': thread[12],98        }99        thread_list[int(thread['id'])] = thread100    return thread_list101def vote(id, vote):102    print("entered")103    try:104        # DBconnect.exist(entity="thread", identifier="id", value=id)105        if vote == -1:106            DBconnect.update_query("UPDATE thread SET dislikes=dislikes+1, points=points-1 where id = %s", (id, ))107        else:108            DBconnect.update_query("UPDATE thread SET likes=likes+1, points=points+1  where id = %s", (id, ))109    except Exception as e:110        print(e.message)111    return details(id=id, related=[])112def open_close_thread(id, isClosed):113    DBconnect.exist(entity="thread", identifier="id", value=id)114    DBconnect.update_query("UPDATE thread SET isClosed = %s WHERE id = %s", (isClosed, id, ))115    response = {116        "thread": id117    }118    return response119def update_thread(id, slug, message):120    DBconnect.exist(entity="thread", identifier="id", value=id)121    DBconnect.update_query('UPDATE thread SET slug = %s, message = %s WHERE id = %s', (slug, message, id, ))122    return details(id=id, related=[])123def thread_list(entity, identifier, related, params):124        # DBconnect.exist(entity="user", identifier="email", value=identifier)125    query = "SELECT date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts " \126            "FROM thread WHERE " + entity + " = %s "127    parameters = [identifier]128    if "since" in params:129        query += " AND date >= %s"130        parameters.append(params["since"])131    if "order" in params:132        query += " ORDER BY date " + params["order"]133    else:..._test_command.py
Source:_test_command.py  
...19amount = 1.220server = Server('http://127.0.0.1:8000')21def main():22    print server.getbalance('wallet0',None)23    # thread.start_new_thread(createw,('a',))24    # thread.start_new_thread(createw,('b',))25    # thread.start_new_thread(createw,('c',))26    # thread.start_new_thread(createw,('d',))27    # thread.start_new_thread(createw,('e',))28    # thread.start_new_thread(createw,('f',))29    # thread.start_new_thread(createw,('g',))30    # thread.start_new_thread(createw,('h',))31    # thread.start_new_thread(createw,('i',))32    # thread.start_new_thread(createw,('j',))33    # thread.start_new_thread(createw,('k',))34    # thread.start_new_thread(createw,('l',))35    # thread.start_new_thread(createw,('m',))36    # thread.start_new_thread(createw,('n',))37    # thread.start_new_thread(createw,('aa',))38    # thread.start_new_thread(createw,('cc',))39    # thread.start_new_thread(createw,('dd',))40    # thread.start_new_thread(createw,('ee',))41    # thread.start_new_thread(createw,('ff',))42    # thread.start_new_thread(createw,('ccc',))43    # thread.start_new_thread(createw,('qq',))44    # thread.start_new_thread(createw,('as',))45    # thread.start_new_thread(createw,('ss2',))46    # thread.start_new_thread(createw,('asd',))47    # thread.start_new_thread(createw,('ds',))48    # thread.start_new_thread(createw,('dsa',))49    # thread.start_new_thread(createw,('dasd',))50    # thread.start_new_thread(createw,('ssas',))51    # thread.start_new_thread(createw,('fss',))52    # thread.start_new_thread(createw,('tf',))53    # thread.start_new_thread(createw,('tfs',))54    # thread.start_new_thread(createw,('sew',))55    # thread.start_new_thread(createw,('sdfe',))56    # thread.start_new_thread(createw,('fde',))57    # thread.start_new_thread(createw,('sdf',))58    # for i in range(70):59    #     createw(i)60    #     i += 161    # thread.start_new_thread(m1)62    # thread.start_new_thread(m2)63    # thread.start_new_thread(m3)64    # thread.start_new_thread(m4)65    # thread.start_new_thread(m5)66    raw_input()67def createw(name):68    wname = 'wallet' + str(name)69    s = server.rpcCreate(wname,None)70    print s71def m1():72    # res = server.listaddresses('default_wallet')73    res = server.publish('3', 'hetao000bgyy001', 0.15, metadata, contentType, sourceHash, currency, amount)74    print res75def m2():76    # res = server.listaddresses('1')77    res = server.publish('6', 'hetao000bgyy002', 0.15, metadata, contentType, sourceHash, currency, amount)78    print res79def m3():...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
