How to use _serve_connection method in fMBT

Best Python code snippet using fMBT_python

server.py

Source:server.py Github

copy

Full Screen

...166 rns.to_remote.flush()167 return cPickle.load(rns.from_remote)168def _remote_close(ns):169 del _g_remote_namespaces[ns]170def _serve_connection(conn):171 global _g_async_rv_counter172 if isinstance(conn, client.Connection):173 to_client = conn._to_server174 from_client = conn._from_server175 else: # conn is a connected socket176 to_client = conn.makefile("w")177 from_client = conn.makefile("r")178 if opt_debug:179 daemon_log("connected %s:%s" % conn.getpeername())180 while 1:181 try:182 obj = cPickle.load(from_client)183 if opt_debug:184 daemon_log("%s:%s => %s" % (conn.getpeername() + (obj,)))...

Full Screen

Full Screen

tasks.py

Source:tasks.py Github

copy

Full Screen

...176 'task_id': new_task['id'],177 'notifier': gevent.event.Event(),178 'accept_socket': s,179 'event': gevent.spawn(180 lambda: _serve_connection(181 api, watch))}182 return generic.http_response(200, request=watch)183 # otherwise, just tail184 data = _generate_data(conn, s)185 return flask.Response(data, mimetype='text/plain')186@bp.route('/<task_id>/logs/<transaction>', methods=['GET'])187def task_log_tail(task_id, transaction):188 if not transaction in watched_tasks:189 flask.current_app.logger.error(190 '%s not in watched tasks: %s' % (transaction,191 watched_tasks))192 return generic.http_notfound()193 watched_tasks[transaction]['notifier'].set()194 # yield to greenlets195 gevent.sleep(0)196 if not 'generator' in watched_tasks[transaction]:197 # something very wrong here198 flask.current_app.logger.error(199 'no generator in %s: %s' % (200 transaction,201 watched_tasks[transaction]))202 watched_tasks.pop(transaction)203 return generic.http_notfound()204 return flask.Response(watched_tasks[transaction]['generator'],205 mimetype='text/plain')206def _generate_data(listen_socket, accept_socket, watch=None):207 logger = logging.getLogger('opencenter.webapp.tasks')208 def generate(sock_in):209 sock_in.settimeout(30)210 while True:211 data = sock_in.recv(1024)212 if not data:213 # remote disconnected214 return215 yield data216 sock_in.close()217 accept_socket.close()218 try:219 watched_tasks.pop(watch)220 except KeyError:221 pass222 logger.debug('Woke up -- spinning generator')223 wrapped_socket = gevent.socket.fromfd(listen_socket.fileno(),224 socket.AF_INET,225 socket.SOCK_STREAM)226 return generate(wrapped_socket)227def _serve_connection(api, watch):228 logger = logging.getLogger('opencenter.webapp.tasks')229 watch_info = watched_tasks[watch]230 listen_socket = watch_info['socket']231 accept_socket = watch_info['accept_socket']232 logger.debug('Waiting for wakeup')233 # we'll wait for the follow-up request234 if watch_info['notifier'].wait(30):235 # we've been woken up -- someone is236 # asking for the file. We should have237 # a response now.238 watch_info['generator'] = _generate_data(listen_socket,239 accept_socket,240 watch)241 # we'll wait 30 seconds for the other side to pick it up......

Full Screen

Full Screen

plc.py

Source:plc.py Github

copy

Full Screen

...177 data = types.SimpleNamespace(addr=addr, inb=b"", outb=b"")178 events = selectors.EVENT_READ | selectors.EVENT_WRITE179 sel.register(conn, events, data=data)180 self.__queues[addr] = queue.Queue()181 def _serve_connection(key, mask):182 """183 Отправка данных по параметрам клиентам.184 """185 sock = key.fileobj186 data = key.data187 if mask & selectors.EVENT_READ:188 recv_data = sock.recv(1024)189 if recv_data:190 data.outb += recv_data191 else:192 self.__queues.pop(sock.getpeername())193 sel.unregister(sock)194 sock.close() 195 if mask & selectors.EVENT_WRITE:196 try:197 data.outb += self.__queues[sock.getpeername()].get_nowait()198 except queue.Empty:199 pass200 if data.outb:201 sent = sock.send(data.outb)202 data.outb = data.outb[sent:]203 while self.__run_socket == True:204 events = sel.select(timeout=0)205 for key, mask in events:206 if key.data is None:207 _accept(key.fileobj)208 else:209 try:210 _serve_connection(key, mask)211 except OSError:212 pass213 events = sel.select(timeout=0)214 for key, mask in events:215 sock = key.fileobj216 self.__queues.pop(sock.getpeername())217 sel.unregister(sock)218 sock.close()219 sel.close()220 self.__selector = None221 def stop_socket(self):222 """223 Остановка сокет-сервера.224 """...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful