Skip to main content

rabbitmq-subprocess-client is a RabbitMQ client (based on `pika`) spawning tasks as subprocess, allowing handling segfault gracefully.

Project description

RabbitMQ-subprocess-client

RabbitMQ-subprocess-client is a RabbitMq client (based on pika) spawning tasks as subprocess, allowing handling segfault gracefully.

Install

pip install rabbitmq-subprocess-client

usage

import os
from concurrent.futures import TimeoutError
import traceback
from rabbitmq_subprocess_client import Runner, Consumer

class MyConsumer(Consumer):
    def consume_main(self, basic_deliver, msg):
        print(f'pre-processing message: {msg} in process: {os.getpid()}')
        try:
            args = []
            kwargs = {}
            self.exec(msg, *args, **kwargs)  # This will run the consume_subprocess method in a subprocess
            self.acknowledge_message(basic_deliver.delivery_tag)
        except TimeoutError:
            self.nacknowledge_message(basic_deliver.delivery_tag)
        except BaseException:
            exc_msg = traceback.format_exc()
            print(exc_msg)
            self.nacknowledge_message(basic_deliver.delivery_tag)

    @staticmethod
    def consume_subprocess(msg, *args, **kwargs):
        print(f'processing message: {msg} in process: {os.getpid()}')

worker = Runner(
    'my_queue', 
    MyConsumer, 
    host="127.0.0.1",
    port="5672",
    user="guest",
    password="guest",
    timeout=None,
)
worker.run()

develop

poetry shell
poetry install
pytest
pre-commit install

Publish new version

poetry publish --build --username= --password=

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rabbitmq_subprocess_client-1.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file rabbitmq_subprocess_client-1.0.1.tar.gz.

File metadata

  • Download URL: rabbitmq_subprocess_client-1.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.10.10 Linux/6.2.8-arch1-1

File hashes

Hashes for rabbitmq_subprocess_client-1.0.1.tar.gz
Algorithm Hash digest
SHA256 71abcba552cb720d77a0e80d634e51a8ad42cafcda7482b3cfabe54b44a27f91
MD5 ff4e0d75f62934d4f5736344922fd1a6
BLAKE2b-256 141d0f5660586f5d9afdf4581e19ca4464a889e12590b1dfeb429193a051d14d

See more details on using hashes here.

File details

Details for the file rabbitmq_subprocess_client-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rabbitmq_subprocess_client-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c0256aebca4eefe3501f9ca553f04fba4e7d38dac5d257b88cca1dff8125e985
MD5 301bb3137f3349e5afaf4f269643bf7e
BLAKE2b-256 31ee30aa4914635e8aca39cd74f75a6e9a322036e3d7891834db325f5b3427ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page