Beispiel #1
0
 def _run_in_thread(self, *args, **kwargs):
     reactor = getattr(self, reactor_name)
     sync = getattr(self, sync_name)
     threadpool = getattr(self, threadpool_name)
     original = getattr(sync, method_name)
     return deferToThreadPool(reactor, threadpool,
                              preserve_context(original), *args, **kwargs)
Beispiel #2
0
 def _run_in_thread(self, *args, **kwargs):
     reactor = getattr(self, reactor_name)
     sync = getattr(self, sync_name)
     threadpool = getattr(self, threadpool_name)
     original = getattr(sync, method_name)
     return deferToThreadPool(
         reactor, threadpool, preserve_context(original), *args, **kwargs
     )
Beispiel #3
0
#!/usr/bin/env python
"""
Example of an Eliot action context spanning multiple threads.
"""

from __future__ import unicode_literals

from threading import Thread
from sys import stdout

from eliot import to_file, preserve_context, start_action
to_file(stdout)


def add_in_thread(x, y):
    with start_action(action_type="in_thread", x=x, y=y) as context:
        context.add_success_fields(result=x + y)


with start_action(action_type="main_thread"):
    # Preserve Eliot context and restore in new thread:
    thread = Thread(target=preserve_context(add_in_thread),
                    kwargs={
                        "x": 3,
                        "y": 4
                    })
    thread.start()
    # Wait for the thread to exit:
    thread.join()
Beispiel #4
0
 def on_any_event(self, event):
     with ANY_INOTIFY_EVENT(path=event.src_path, event=event):
         reactor.callFromThread(
             preserve_context(self.process),
             event,
         )
Beispiel #5
0
 def on_any_event(self, event):
     with ANY_INOTIFY_EVENT(path=event.src_path, event=event):
         reactor.callFromThread(
             preserve_context(self.process),
             event,
         )
Beispiel #6
0
#!/usr/bin/env python

"""
Example of an Eliot action context spanning multiple threads.
"""

from __future__ import unicode_literals

from threading import Thread
from sys import stdout

from eliot import to_file, preserve_context, start_action
to_file(stdout)


def add_in_thread(x, y):
    with start_action(action_type="in_thread", x=x, y=y) as context:
        context.add_success_fields(result=x+y)


with start_action(action_type="main_thread"):
    # Preserve Eliot context and restore in new thread:
    thread = Thread(target=preserve_context(add_in_thread),
                    kwargs={"x": 3, "y": 4})
    thread.start()
    # Wait for the thread to exit:
    thread.join()