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

Better shutdown #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Better shutdown #14

wants to merge 1 commit into from

Conversation

Silex
Copy link
Contributor

@Silex Silex commented Dec 12, 2016

Only the last commit is relevant here, as the others are from #13

I'll rebase this PR onces #13 is merged.

This basically removes all the foo.kill. It looks like "it works" but I didn't give it a lot of testing.

By the way, does https://github.com/Silex/mjpeg-relay/blob/217904d862cade494d031667d9e30884a9e1e34d/relay.py#L26 really make sense? I know it works, but theorically how can quit() access global variables here? I guess I don't know python enough 😝

I think it's simpler to move the quit() body at the bottom of the try block, and remove the quit() calls. There's no real need to have multiple exit paths.

I was thinking of refactoring a bit more and replacing the foo.connected thing with a function instead, that way we can get rid of the variable and the check is always accurate (simply return the socket state).

Also, each of these "servers" should have a saner start/stop mechanism. At the moment the thread thing for each of them is a bit weird... not the thread in itself but its permanence. I think in general, "start" should start listening/open the socket and spawn a thread, and stop should close the socket/server and kill the thread.

I'll see what I can do, and ping you when I have something. Give me your thoughts in the meantime 😉

p.s: you code on windows? I was a bit surprised by the windows line endings.

self.acceptThread.start()

def stop(self):
self.acceptsock.close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work correctly when we're listening for clients on line 103 in a different thread but with the same socket? If this does properly close the port on Windows and Linux then this is much cleaner. The reason it used the kill flag and the quitsock is to avoid acting on the socket from two different threads. Perhaps this works fine though, I haven't tested.

@OliverF
Copy link
Owner

OliverF commented Dec 13, 2016

Regarding foo.kill please see my comment on the code.

quit() works but I suppose it should mark the variables as global scope. A better solution is to just pass them as parameters!

Making foo.connected a function makes sense, that way we can get the true value of the socket like you say.

And I agree, the start/stop needs a re-think :)

P.S. yes I do - I love Linux and I'd switch in a heartbeat, but sadly a lot of my programs run on Windows only. One day :)

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

Successfully merging this pull request may close these issues.

2 participants