Popular recipes by Vovan http://code.activestate.com/recipes/users/4192447/2015-06-30T03:37:19-07:00ActiveState Code RecipesSimple Web socket client implementation using Tornado framework. (Python) 2015-06-30T03:37:19-07:00Vovanhttp://code.activestate.com/recipes/users/4192447/http://code.activestate.com/recipes/579076-simple-web-socket-client-implementation-using-torn/ <p style="color: grey"> Python recipe 579076 by <a href="/recipes/users/4192447/">Vovan</a> (<a href="/recipes/tags/client/">client</a>, <a href="/recipes/tags/tornado/">tornado</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/websocket/">websocket</a>, <a href="/recipes/tags/websockets/">websockets</a>). </p> <p>Simple Web socket client implementation using Tornado framework.</p> De-chunk and decompress HTTP body (Python) 2015-06-30T03:31:31-07:00Vovanhttp://code.activestate.com/recipes/users/4192447/http://code.activestate.com/recipes/579075-de-chunk-and-decompress-http-body/ <p style="color: grey"> Python recipe 579075 by <a href="/recipes/users/4192447/">Vovan</a> (<a href="/recipes/tags/chunked/">chunked</a>, <a href="/recipes/tags/content/">content</a>, <a href="/recipes/tags/dechunking/">dechunking</a>, <a href="/recipes/tags/decompression/">decompression</a>, <a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/preprocess/">preprocess</a>, <a href="/recipes/tags/transfer/">transfer</a>). Revision 2. </p> <p>Example read_body_stream() usage:</p> <pre class="prettyprint"><code>with open(http_file_path, 'rb') as fh: print(b''.join(httputil.read_body_stream( fh, chunked=True, compression=httputil.GZIP)) </code></pre> Consumer Application Skeleton (Python) 2015-06-30T03:24:07-07:00Vovanhttp://code.activestate.com/recipes/users/4192447/http://code.activestate.com/recipes/579074-consumer-application-skeleton/ <p style="color: grey"> Python recipe 579074 by <a href="/recipes/users/4192447/">Vovan</a> (<a href="/recipes/tags/application/">application</a>, <a href="/recipes/tags/consumer/">consumer</a>, <a href="/recipes/tags/daemon/">daemon</a>, <a href="/recipes/tags/framework/">framework</a>). Revision 2. </p> <h4 id="consumer-application-skeleton">Consumer Application Skeleton</h4> <p>This is very basic skeleton for data processing application implementing consumer pattern:</p> <pre class="prettyprint"><code>while is_running(): task = get_next_task_from_queue() if task: submit_task_for_processing(task) else: sleep_for_a_moment() </code></pre> <p>Here's an example:</p> <pre class="prettyprint"><code>class ExampleApp(ConsumerAppBase): def _get_next_task(self): # Get next task from the queue. return self._queue.next() def _run_task(self, task): # This code's being executed in separate worker thread of # ThreadPoolExecutor return task / 2 def _on_task_done(self, task, future): # Once worker thread finished - task results are available # in _on_task_done() callback as a concurrent.futures.Future object. self._log.info('Task done. Result: %s', future.result()) </code></pre>