Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Fine tune control over processing #50

Closed
washcycle opened this issue Feb 3, 2019 · 4 comments
Closed

Feature - Fine tune control over processing #50

washcycle opened this issue Feb 3, 2019 · 4 comments

Comments

@washcycle
Copy link
Contributor

I was thinking about creating a pull request to take the _serverProcess function and the ability to run the process outside in a while loop at the parent thread process.

def _serverProcess(self) :
    self._started = True
    while True :
        try :
            client, cliAddr = self._server.accept()
        except Exception as ex :
            if ex.args and ex.args[0] == 113 :
                break
            continue
        self._client(self, client, cliAddr)
    self._started = False

Proposed Addition

def serverProcessOneCycle(self) :
    try :
        client, cliAddr = self._server.accept()
    except Exception as ex :
        if ex.args and ex.args[0] == 113 :
            return
    self._client(self, client, cliAddr)

Example Usage

from microWebSrv import MicroWebSrv
mws = MicroWebSrv()                                    # TCP port 80 and files in /flash/www
mws.MaxWebSocketRecvLen     = 256                      # Default is set to 1024
mws.WebSocketThreaded       = False                    # WebSockets without new threads
mws.AcceptWebSocketCallback = _acceptWebSocketCallback # Function to receive WebSockets

mws.Init() ## not sure about this first init part

def some_process():
    #something awesome

whilte True:
    some_process()
    try:
        mws.serverProcessOneCycle()
   except:
       print("something went wrong")

Any thoughts, perhaps I didn't consider an already present micropythonic way to do this.

@jczic
Copy link
Owner

jczic commented Feb 3, 2019

Hi,
If you want to do that, without thread, you just can stop the server in the client connection callback event, no ? :)

@washcycle
Copy link
Contributor Author

washcycle commented Feb 4, 2019 via email

@jczic
Copy link
Owner

jczic commented Feb 4, 2019

No, because in any case, this is in the processing of the reception of the client socket that allows to close the server properly. The loop then comes out immediately (err #113) :)
No problem.

@jczic jczic closed this as completed Feb 4, 2019
@jczic
Copy link
Owner

jczic commented Oct 20, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants