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 / 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:
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:
@mattbennett
mattbennett / repro.py
Last active March 9, 2018 17:29
Kombu unsafe default socket timeout
from kombu import Connection
import time
import threading
import socket
AMQP_URI = "pyamqp://guest:guest@localhost:5672/"
DEFAULT_TIMEOUT = 1.0
+-----------+
| |
| Gateway |
| |
+-----------+
| |
+-------+ +-------+
| |
+-----v-----+ +-----v-----+
| | | |
FROM debian:stretch
RUN apt-get update
RUN apt-get install -y python3 python3-pip erlang rabbitmq-server unixodbc unixodbc-dev
RUN pip3 install pyodbc apscheduler nameko
COPY config.yaml /srv/config.yaml
COPY service.py /srv/service.py
CMD /etc/init.d/rabbitmq-server start; cd /srv; nameko run service --config config.yaml
@mattbennett
mattbennett / growing.py
Last active May 1, 2017 10:01
Eventlet memory leak
import eventlet
import eventlet.debug
eventlet.debug.hub_exceptions(False)
import objgraph
import gc
import uuid
threads = {}
@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:
""" 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