Open Fhrozen opened 4 years ago
one more time: https://github.com/K6L6/viewpoint-optimization/blob/509c34335821b5a29db44581c72623ab7aa5a45e/SocketServer.py#L63-L66
if you call like that in the init, then you will not be able to call them.
When you have variable defined inside a method (def) then all the variables will be lost once the method is finished. Inside a class you can avoid it using self.model = ...
I renamed the script to GQNServer.py and the client is socket-client.py, these two scripts can send and accept data from each other, after I changed the encoding and decoding function. I think I didn't implement the GQN data processing thread well because I confirmed that it only runs the first time. The GQN thread won't start when another set of data is sent to the server...
I supposed that you mean the lack of a loop:
From this line it should be a loop, otherwise it will just run once.
https://github.com/K6L6/viewpoint-optimization/blob/74b155b2d4a3a992d3bc5829d5e7cf2eecda8ade/GQNServer.py#L100
Put a while True:
before that line and it should be fine.
I guess? I want the gqn_process() to run again when it gets a new data, but I don't want it to use the same data and calculate over and over again while waiting for new data? (do I use a flag in while loop and change the value from False to True for new data...?) I'm not sure how this part works, because it seems that gqn_process() won't run until it gets data from the client: https://github.com/K6L6/viewpoint-optimization/blob/74b155b2d4a3a992d3bc5829d5e7cf2eecda8ade/GQNServer.py#L260-L264
I thought that the input is just anything it gets from the queue object data_recv, but the process won't run even if data_recv is None. So I'm not sure how the queue object works... https://github.com/K6L6/viewpoint-optimization/blob/74b155b2d4a3a992d3bc5829d5e7cf2eecda8ade/GQNServer.py#L84
You will need to add something like this before the previous line:
while data_recv.empty():
sleep(0.01)
inp = data_recv.get()
if isinstance(inp, list):
observed_viewpoint, observed_image, offset = data_recv.get()
Remember that data_recv.get() just gets the data if there is one, even Nones. if it is empty then it does not works.
I found this basic tuto on multithreading and queue. You may check it. I hope it is easy to understand: https://www.troyfawkes.com/learn-python-multithreading-queues-basics/
I will write down here the errors I see in the code for SocketServer.py