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

Web based GUI #40

Open
neilthomson opened this issue Aug 19, 2015 · 2 comments
Open

Web based GUI #40

neilthomson opened this issue Aug 19, 2015 · 2 comments

Comments

@neilthomson
Copy link

This probably isn't an issue but wasn't sure where else to post.

I'm trying to develop a web based GUI for pi camera using the Flask framework, except I'm running into port address issues and I don't know enough about socket.io or networking to know how to try and solve it.

If you create an instance of CompoundPiClient in or above the Flask instance in the same script file you get.

  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use

Which doesn't happen if you run a Flask instance and cpi separately, all seem fine and dandy, but not if they are in the same script.

Any ideas?

@waveform80
Copy link
Member

CompoundPiClient opens a TCP listening socket to deal with downloads from the servers, therefore there firstly you need to make sure there's nothing using port 5647 on the client (I doubt this is the problem) and secondly you need to make sure that only a single instance of CompoundPiClient exists at any given time (this is very likely the issue given the way web frameworks like Flask et al operate multiple threads/processes/whatever to deal with multiple client requests). It's the same issue as trying to make a web interface for the camera generally and finding you can't instantiate more than a single copy of PiCamera at a given time (I've had plenty of e-mail about that! :).

Basically you'll need to create a single global CompoundPiClient and lock access to it, to ensure that no more than a single web-client uses it for a given transaction (it's not thread-safe and there's little point in attempting to make it so).

@neilthomson
Copy link
Author

Thanks for the feedback.

I did briefly make the PiClient a 'borg' class (http://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/) before I started playing with Flask. I guess this wouldn't be threadsafe as clients could simultaneously create requests that would clash, causing havoc with PiSevers? In a simple script it did work, all instances shared their state so I could run more than one instance - to do so I had to put everything from init into a 'boot_strap' method that would try / except variables to see if they were all ready set on running.

Now checking out PySide/Qt :)

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