示例#1
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        try:
            self.__api.subscribe('python_c', self.request)

            result = self.__api.poll()
            assert result == False
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate msg_size python_c')

    def request(self, command, name, pattern, request_info, request,
                timeout, priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print('forward #%d python_c to %s (with timeout %d ms)' % (
            i, _DESTINATION, timeout,
        ))
        self.__api.forward_(command, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)
示例#2
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        self.__api.subscribe('python_c', self.request)

        result = self.__api.poll()
        print 'exited thread:', result

    def request(self, command, name, pattern, request_info, request, timeout,
                priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print 'forward #%d python_c to %s (with timeout %d ms)' % (
            i,
            _DESTINATION,
            timeout,
        )
        self.__api.forward_(command, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)
示例#3
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        try:
            self.__api.subscribe('python_c', self.request)

            result = self.__api.poll()
            assert result == False
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate msg_size python_c')

    def request(self, request_type, name, pattern, request_info, request,
                timeout, priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print('forward #%d python_c to %s (with timeout %d ms)' % (
            i, _DESTINATION, timeout,
        ))
        self.__api.forward_(request_type, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)
示例#4
0
def _main():
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [_Task(API(thread_index))
               for thread_index in range(thread_count)]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
示例#5
0
文件: count_c.py 项目: sekmet/CloudI
def _main():
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [Task(API(thread_index), 'python_c', TerminateException)
               for thread_index in range(thread_count)]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
示例#6
0
 def __disconnect(self, request_type, name, pattern, request_info, request,
                  timeout, priority, trans_id, pid):
     # pylint: disable=unused-argument
     # pylint: disable=too-many-arguments
     assert request == b'DISCONNECT'
     print('disconnect: %s' % str(API.info_key_value_parse(request_info)))
     return ''
示例#7
0
def _main():
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [Task(API(thread_index), 'python_c', TerminateException)
               for thread_index in range(thread_count)]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
示例#8
0
文件: echo.py 项目: CloudI/CloudI
def _main():
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [_Task(API(thread_index))
               for thread_index in range(thread_count)]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
示例#9
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        self.__api.subscribe("python_c", self.request)

        result = self.__api.poll()
        print "exited thread:", result

    def request(self, command, name, pattern, request_info, request, timeout, priority, trans_id, pid):
        i = struct.unpack("=I", request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack("=I", i) + request[4:]
        print "forward #%d python_c to %s (with timeout %d ms)" % (i, _DESTINATION, timeout)
        self.__api.forward_(command, _DESTINATION, request_info, request, timeout, priority, trans_id, pid)
示例#10
0
            self.__check_environment()
            # idle service with no subscriptions
            result = self.__api.poll()
            assert result == False
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate environment python_c')

    def __check_environment(self):
        user = os.environ.get('USER')
        assert user is not None
        assert os.environ[user] == 'user'
        assert os.environ[user + '_' + user] == 'user_user'
        assert os.environ[user + user] == 'useruser'
        assert os.environ[user + '123' + user] == 'user123user'
        assert os.environ['USER_D'] == 'user_$'
        assert os.environ['USER_'] == 'user_'


if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [Task(API(i)) for i in range(thread_count)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()
示例#11
0
 def __init__(self, thread_index):
     threading.Thread.__init__(self)
     self.__api = API(thread_index)
示例#12
0
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate msg_size python_c')

    def request(self, command, name, pattern, request_info, request,
                timeout, priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print('forward #%d python_c to %s (with timeout %d ms)' % (
            i, _DESTINATION, timeout,
        ))
        self.__api.forward_(command, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)

if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1
    
    threads = [_Task(i) for i in range(thread_count)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()

示例#13
0
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#

import sys, os
sys.path.append(
    os.path.sep.join(
        os.path.dirname(os.path.abspath(__file__)).split(os.path.sep)[:-2] +
        ['api', 'python']))

from cloudi_c import API
from messaging import Task

if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [Task(API(i), i, 'python_c') for i in range(thread_count)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()
示例#14
0
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#

import sys, os
sys.path.append(
    os.path.sep.join(
        os.path.dirname(os.path.abspath(__file__)).split(os.path.sep)[:-2] +
        ['api', 'python']))

from cloudi_c import API, terminate_exception
from http_req import Task

if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [
        Task(API(i), 'python_c', terminate_exception)
        for i in range(thread_count)
    ]
    for t in threads:
        t.start()
    for t in threads:
        t.join()
示例#15
0
 def __init__(self, thread_index):
     threading.Thread.__init__(self)
     self.__api = API(thread_index)
示例#16
0
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate msg_size python_c')

    def request(self, request_type, name, pattern, request_info, request,
                timeout, priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print('forward #%d python_c to %s (with timeout %d ms)' % (
            i, _DESTINATION, timeout,
        ))
        self.__api.forward_(request_type, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)

if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1
    
    threads = [_Task(i) for i in range(thread_count)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()