Skip to content

Instantly share code, notes, and snippets.

View mattbennett's full-sized avatar

Matt Yule-Bennett mattbennett

  • London, England
View GitHub Profile
@mattbennett
mattbennett / .gitignore
Last active November 2, 2023 10:38
Nameko websocket test
*.pyc
@mattbennett
mattbennett / client.py
Last active July 7, 2022 19:38
Greenthread worker
import eventlet
eventlet.monkey_patch()
from eventlet.greenpool import GreenPile
from kombu.pools import producers
from kombu import Exchange, Queue
exchange = Exchange('exchange', type='direct')
queue = Queue('queue', exchange, routing_key='queue')
@mattbennett
mattbennett / client.py
Created April 14, 2017 15:00
Nameko Auth Toy
from nameko.standalone.rpc import ClusterRpcProxy
config = {
'AMQP_URI': 'amqp://guest:guest@localhost:5672/'
}
with ClusterRpcProxy(config) as rpc:
session_token = rpc.auth.login("admin", "secret")
with ClusterRpcProxy(config, context_data={'session': session_token}) as rpc:
@mattbennett
mattbennett / app.py
Last active November 19, 2021 10:12
Nameko celery integration
from flask import Flask, request
from nameko.standalone.rpc import ServiceRpcProxy
app = Flask(__name__)
@app.route('/')
def task_list():
return """
<html>
@mattbennett
mattbennett / client.py
Last active November 23, 2020 21:31
Nameko call_async performance
from nameko.standalone.rpc import ClusterRpcProxy
from time import perf_counter, sleep
import pkg_resources
config = {
"AMQP_URI": "amqp://guest:guest@localhost:5672" # e.g. "pyamqp://guest:guest@localhost"
}
with ClusterRpcProxy(config) as cluster_rpc:
""" Regression tests for https://github.com/nameko/nameko/issues/428
The tests in this module show detailed examples of possible failures caused
by the above bug. It's being left here rather than in the repo since the tests
themselves are quite slow, and one is sufficient to verify the regression.
"""
import itertools
import time
from functools import partial
@mattbennett
mattbennett / .coveragerc
Last active March 4, 2020 05:59
coverage subprocess
[run]
branch = True
source = .
from setuptools import setup, find_packages
setup(
name='MyPackageName',
version='1.0.0',
url='https://github.com/mypackage.git',
author='Author Name',
author_email='author@gmail.com',
description='Description of my package',
packages=[],
@mattbennett
mattbennett / .gitignore
Last active March 13, 2019 12:11
Nameko gRPC Example
*_pb2.py
*_pb2_grpc.py
__pycache__
@mattbennett
mattbennett / attach_pdb.py
Created June 26, 2018 09:25
Attach PDB to Nameko worker exceptions
@pytest.yield_fixture
def pdb_worker_exceptions():
import pdb
from mock import patch
from nameko.containers import ServiceContainer
unpatched = ServiceContainer._worker_result
def attach_pdb(self, worker_ctx, result, exc_info):
if exc_info: