Hello! I have a socket server in Python. It keeps in memory an array of users connected to it at a given time with their data (age allowed). Where in such a system to make an infinite loop looking for the same people by age? Any parallel flow can do?

In such cases, it turns out the launch of this server on python is the opening of a port for receiving web sockets, the start of an infinite loop in a parallel stream. Will this infinite loop in parallel flow work with the current array of connected users to the socket? Advise how to make such a search more correctly among connected people?

  • And why endlessly look for the same age. Found once, the array ended, then what to look for, before connecting the next one - Mike
  • And how do you propose to do this only when you connect? Suppose the two are connected - that now drive the same cycle twice? I thought it would be right to do this: turn while (true) and there is a cycle in it to search for similar people in an array, which is changed by other processes. If there are suggestions how to start / stop this cycle (at the same time, check whether it is already started by another user) - write, please, the tornado framework. I do it through IOLoop.instance (). Add_callback - iproger
  • it is not clear why cycles at all. Build a hash of arrays or lists by year of birth. - Mike
  • Well, the hash is okay, not the essence; we don’t touch the mechanism of directly searching for people. And the endless loop is for this. Suppose all this works without an infinite loop. Two suitable friends of the durga have connected, if we don’t have one infinite loop processing connected people, then the connected person will launch a check mechanism for the people who are suitable for it, so also the one he is looking for also starts this mechanism. Total: there will be 2 alerts that a person has been found will be dubbing. So one mechanism should be responsible for this. Please describe how you see it - iproger
  • And an endless cycle will endlessly find matching people and there will be endless dubbing. In any case, you have already been told about whom. And what is actually dubbing. If you have a multi-threaded application, then the beginning of the search takes a lock that would only work in 1 thread at a time. looking for everyone who is at the moment, reports them, removes the lock. The second process begins to search - all suitable and informs them only about themselves. And he was not on the list yet, while the first one was looking for - Mike

0