I have created a custom Python OpenDXL client using the bootstrapper (which I found here: OpenDXL Bootstrap Application.). The intention is to use this client to send requests to a service on the DXL fabric and get a response. To test it, I modified the built-in sample that comes with bootstrap-generated files.
When I run my code using python -m P2InternalClient <config-directory> I don't have any problems and everything works perfectly fine. However, I want to use this as an installed library that can have a client that extends the P2InternalClient to use as a normal DXL client.
I used the bootstrap distribution script to create a .whl and install it using PIP without any problem. However, when I try to use the modified sample code to import the installed module, I get this error:
[IMG:https://i.imgur.com/GCGunXQ.png]
I have no idea what this is referring to with the _lock attribute.
Client Code:
If it helps, I've included a version of the client class that can cause the issue (see below)
- import logging
- from dxlbootstrap.app import Application
- from eventhandlers import *
- # Configure local logger
- logger = logging.getLogger(__name__)
- class P2InternalClient(Application):
- """
- The "P2 Internal Client" application class.
- """
- def __init__(self, config_dir):
- """
- Constructor parameters:
- :param config_dir: The location of the configuration files for the
- application
- """
- super(P2InternalClient, self).__init__(config_dir, "opendxl-p2.config")
- @property
- def client(self):
- """
- The DXL client used by the application to communicate with the DXL
- fabric
- """
- return self._dxl_client
- @property
- def config(self):
- """
- The application configuration (as read from the "opendxl-p2.config" file)
- """
- return self._config
- def on_run(self):
- """
- Invoked when the application has started running.
- """
- logger.info("On 'run' callback.")
- def on_load_configuration(self, config):
- """
- Invoked after the application-specific configuration has been loaded
- This callback provides the opportunity for the application to parse
- additional configuration properties.
- :param config: The application configuration
- """
- logger.info("On 'load configuration' callback.")
- def on_dxl_connect(self):
- """
- Invoked after the client associated with the application has connected
- to the DXL fabric.
- """
- logger.info("On 'DXL connect' callback.")
- def on_register_event_handlers(self):
- """
- Invoked when event handlers should be registered with the application
- """
- # Register event callback 'p2internalclient_handler'
- logger.info("Registering event callback: {0}".format("p2internalclient_handler"))
- self.add_event_callback("/p2/request/msgv1/#", P2InternalRequestsCallback(self), True)
Sample Code:
And once the library is installed, here is the sample code that causes the error.
- import os
- import sys
- from dxlclient.client_config import DxlClientConfig
- from dxlclient.client import DxlClient
- from dxlclient.message import Message, Event, Request
- from dxlbootstrap.util import MessageUtils
- # Import common logging and configuration
- sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")
- from common import *
- from opendxlp2 import P2InternalClient
- # Configure local logger
- logging.getLogger().setLevel(logging.ERROR)
- logger = logging.getLogger(__name__)
- # Create DXL configuration from file
- config = DxlClientConfig.create_dxl_config_from_file(CONFIG_FILE)
- # Create the client
- with DxlClient(config) as client:
- # Connect to the fabric
- client.connect()
- p2client = P2InternalClient(client)
- logger.info("Connected to DXL fabric.")
- # Send event that will trigger event callback 'p2internalclient_handler'
- evt = Event("/p2/request/msgv1/#")
- MessageUtils.encode_payload(evt, "p2internalclient_handler event payload")
- client.send_event(evt)
I'm pretty stumped on this, does anyone have any idea what the problem is?