I have a feeling that itβs really not that difficult, but so far I have little success.
Say I have a PikaClass class that wraps pika and provides some business methods.
def PikaClass(object): def __init__(self):
Intuitively, this is what I would like to achieve: the user creates an instance of PikaClass , sets up a loop going in the background, and then interacts with the object, invoking certain business methods
p = PikaClass() p.start() bar = p.foo(..)
The problem is that p.start () blocks and prevents the main code from interacting with the object as soon as start () was called. My first thought was to wrap the call in a thread:
Thread(target=p.start()).start() bar = p.foo(..)
But it still blocks and you never get to p.foo (..). The docs mention that you should not share the link between threads so that something could cause a problem.
I also tried using AsyncoreConnection instead of SelectConnection and directly called _connect () (instead of using ioloop), but this has no effect (nothing happens).
So, how can I launch ioloop in the background or at least run my own ioloop?
Note. This is Python 2.6 on win64 (xp) with the latest pika 0.9.4
source share