Is it possibile to use mutithreading to make OpenOpc read faster OPC items?

Viewed 389

I'm using OpenOPC https://github.com/Alexhll/OpenOPC-python3.6/blob/master/src/OpenOPC.py and opcua libs to make a proxy for opc da (client) to opc da(server). In order to make it work i'm using the metod from OpenOPC

nodes = c.list('*',recursive=True)

to discover all the Nodes of the opc da server. However to discover 10000 items it takes about 3 minutes so i would like to make it faster. By debugging a little bit the OpenOPC libs i found that the line that is much more time consuming is

if lowest_level:  matches = [exceptional(browser.GetItemID,x)(x) for x in matches]

at line 1096. I tought that a good approach could be with multithreading with a pool map however i wansn't able convert it in multithreading beacuse of the decorator. Is it possibile to make this improvement or i'm completely wrong about this idea? what i tryied was this with no luck and i understand beeing wrong.

matches =pool.map(exceptional,matches)

here is the exceptional method from the libs at line 103:

def exceptional(func, alt_return=None, alt_exceptions=(Exception,), final=None, catch=None):
   """Turns exceptions into an alternative return value"""

   def _exceptional(*args, **kwargs):
      try:
         try:
            return func(*args, **kwargs)
         except alt_exceptions:
            return alt_return
         except:
            if catch: return catch(sys.exc_info(), lambda:func(*args, **kwargs))
            raise
      finally:
         if final: final()
   return _exceptional

Thank you for the help!

1 Answers

This is like having a database and query the entire contents at the beginning, that makes little sense to me.

The OPC UA client that I programmed only requests node first-level children every time the user expands the node in the browser.

You cannot use multithreading, a new request cannot be send until you have the reply from the previous one.

Related