J
J
John2016-08-31 18:28:01
Django
John, 2016-08-31 18:28:01

How to solve the problem with the visibility of functions?

I found a library for websockets on the Internet . He knows how to launch a websocket server, listen to messages, send, notify about a new connection, disconnection. I wrote an interface over this lib so that decorators can subscribe to a specific channel, room, event. When a message arrives, the registered functions on which the decorator hangs are called and actions are performed there.
Problem: The
WebSocket server is started separately from the runsocketserver.py file by a command that calls the launch from the websocket.py file

def start():
....
        cls = Manager

        if options['ssl'] == 1:
            server = SimpleSSLWebSocketServer(options['host'], options['port'], cls, options['cert'], options['cert'],
                                              version=options['ver'])
        else:
            server = SimpleWebSocketServer(options['host'], options['port'], cls)
....

There is a manager.py file in which the interface hangs with all sorts of decorators, where channels, rooms, users are stored, in general, everything that I did.
@staticmethod
    def listen(channel, room, event):
        def wrapper(f):
             ....

Decorators hang throughout the project in different files. To listen to the event, did this
@staticmethod
    @WebSocketManager.listen('/', 'chat', 'message')
    def on_message(packet):
        ...

When the server starts, registering these very functions through the decorator does not work. I solved this problem like this. I created a separate settings.py file, there I created a variable where I insert classes that have a decorator and then I import the file locally when the websocket server starts in the websocket.py file:
class SimpleWebSocketServer(object):
    def __init__(self, host, port, websocketclass, selectInterval=0.1):
        ...
        from Websocket.manager import WebSocketManager

Is it possible to make it so that when the file is launched, the file can access files, classes, not the way I did, but differently?
settings.py file
from Test.test import Chat

INSTALLED_MODULES = [
    Chat
]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question