cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
190 stars 109 forks source link

How to reuse thread ID #176

Closed user1493 closed 5 years ago

user1493 commented 5 years ago

I have two method to get the cubes and get the dimensions:

Initially I call cubes() and then dim().

  1. Is it possible to reuse the thread ID which was created during the call cubes()?
  2. Calling these methods multiple times creates new threads (with new thread ID).. will this cause any issue?
def cubes(self):
    with TM1Service(address=address, port=port, user=user,
                    password=password, namespace=namespace, ssl=ssl, gateway=gateway) as tm1:
        print(tm1.cubes.get_all_names())

def dim(self):
    with TM1Service(address=address, port=port, user=user, password=password,
                    namespace=namespace, ssl=ssl, gateway=gateway) as tm1:
        print(tm1.dimensions.get_all_names())
user1493 commented 5 years ago

Just now saw this thread about using Pickle.... this thread solved my issue with threads https://github.com/cubewise-code/tm1py/issues/176#issue-497637567

rclapp commented 5 years ago

I recommend that you explore the tm1py samples. https://github.com/cubewise-code/tm1py-samples In your case you have too many with statements.

On Sep 25, 2019 9:33 AM, user1493 notifications@github.com wrote:

I have two method to get the cubes and get the dimensions:

Initially I call cubes() and then dim().

  1. Is it possible to reuse the thread ID which was created during the call cubes()?
  2. Calling these methods multiple times creates new threads (with new thread ID).. will this cause any issue?

def cubes(self): with TM1Service(address=address, port=port, user=user, password=password, namespace=namespace, ssl=ssl, gateway=gateway) as tm1: print(tm1.cubes.get_all_names())

def dim(self): with TM1Service(address=address, port=port, user=user, password=password, namespace=namespace, ssl=ssl, gateway=gateway) as tm1: print(tm1.dimensions.get_all_names())

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/cubewise-code/tm1py/issues/176?email_source=notifications&email_token=AEK7GZVRC4B7HG76IX23KKDQLIAL3A5CNFSM4IZ6WWV2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HNJLC7Q, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEK7GZSDZUJYB7J2IVVLTWLQLIAL3ANCNFSM4IZ6WWVQ.

cubewise-tryan commented 5 years ago

Hi @user1493,

You need reuse the TM1Service instead of creating a new one in each method.