question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is raven thread and process safe?

See original GitHub issue

When I test it with multi process, my server does not receive any message. I try to find the reason. It seems that the message go to the Queue, but cannot be picked out. In fact, although I config handler for each process, they use the same handler and the same transport object. The worker object block at Queue.get method.

I config the handler like this in each process.

logger = logging.getLogger()
logger.handlers = []
client = Client(os.getenv('SENTRY_DSN'))
handler = SentryHandler(client)
handler.setLevel(logging.ERROR)
logger.addHandler(handler)

The worker object block at this statement. File: raven/transport/threaded.py Line 133, record = self._queue.get()

    def _target(self):
        while True:
            record = self._queue.get()  # This statement blocks.
            try:
                if record is self._terminator:
                    break
                callback, args, kwargs = record
                try:
                    callback(*args, **kwargs)
                except Exception:
                    logger.error('Failed processing job', exc_info=True)
            finally:
                self._queue.task_done()

            sleep(0)

Only the main process send the message successful. Btw, because, my raven version is 5.2.0.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jinzhao1994commented, May 4, 2017

Sorry… I forgot there is a link… I thought they will work with it… In my code, I just write a init log function. This function will be called first in the new process.

def init_log(sentry_dsn, sentry_level=logging.ERROR):
    import raven
    from raven.handlers.logging import SentryHandler
    from raven.transport.registry import TransportRegistry, default_transports
    raven.Raven = None
    raven.Client.logger = logging.getLogger('raven')
    raven.Client._registry = TransportRegistry(transports=default_transports)
    client = raven.Client(sentry_dsn)
    handler = SentryHandler(client)
    handler.setLevel(sentry_level)
    logger.addHandler(handler)

Or you can simply don’t use log before fork process.

0reactions
nateyodercommented, May 5, 2017

@jinzhao1994 Thank you so much for the help! Really appreciate it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

9. Threads — Memory Pool System 1.117.0 documentation
Thread safety ¶. The MPS is designed to run in an environment with multiple threads all calling into the MPS. Some code is...
Read more >
Thread Safety: Class Variables in Ruby - Stack Overflow
This is not actually true. The assumption that class instance variables are threadsafe is also untrue. Having a GIL doesn't make your code ......
Read more >
Process-Safe in Python
Thread safety is a major concern of concurrent programming using threads. This is because threads have shared memory within the process, meaning ...
Read more >
Safe as Life: A Four-Part Essay on Maggie Stiefvater's Raven ...
I: Safe as Life: Complex, Messy Love in The Raven Boys ... the halfway point of the novel where all of their separate...
Read more >
PURE CANNABIS CONCENTRATE - Raven Grass
Our safe-solvent extraction uses >99% purity CO2 and leaves no residual solvent ... Our raw dehydration process purges moisture, yet leaves terpene and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found