Repository: OpenMined/PySyft
Pull request: Avoids multiple peers registration in the same grid environment.
## Description

I just added a `_registered_peer` variable to hold the very first grid peer registration. So, any register made later, within the same runtime, the same instance is returned.

Resolves #3576 


## Checklist:
* [ ] My changes are covered by tests.
* [x] I have run [the pre-commit hooks](https://github.com/OpenMined/PySyft/blob/master/CONTRIBUTING.md#setting-up-pre-commit-hook) to format and check my code for style issues.
* [x] I have commented my code following [Google style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).

(See the [the contribution guidelines](https://github.com/OpenMined/PySyft/blob/master/CONTRIBUTING.md) for additional tips.)


Problem statement:
Calling syft.grid.register() twice should throw an informative error
**Is your feature request related to a problem? Please describe.**
If you call syft.grid.register() twice in the same python runtime it should raise an error describing that you can't do this - that they shoudl restart the python runtime and try again.

Hints from issue discussion:
I'd like to take this one.

Commit message: add user warning message on multiple registration

Patch to review:
diff --git a/syft/grid/__init__.py b/syft/grid/__init__.py
index 2e379fc86f4..2180cd92198 100644
--- a/syft/grid/__init__.py
+++ b/syft/grid/__init__.py
@@ -3,20 +3,27 @@
 
 DEFAULT_NETWORK_URL = "ws://ec2-13-59-45-128.us-east-2.compute.amazonaws.com"
 
+_registered_peer = None
+
 
 def register(**kwargs):
     """ Add this process as a new peer registering it in the grid network.
-        
+
         Returns:
             peer: Peer Network instance.
     """
-    if not kwargs:
-        args = args = {"max_size": None, "timeout": 444, "url": DEFAULT_NETWORK_URL}
-    else:
-        args = kwargs
+    global _registered_peer
 
-    peer_id = str(uuid.uuid4())
-    peer = Network(peer_id, **args)
-    peer.start()
+    if _registered_peer is None:
+        if not kwargs:
+            args = args = {"max_size": None, "timeout": 444, "url": DEFAULT_NETWORK_URL}
+        else:
+            args = kwargs
+
+        peer_id = str(uuid.uuid4())
+        _registered_peer = Network(peer_id, **args)
+        _registered_peer.start()
+    else:
+        raise UserWarning(f"You're already a registered peer {_registered_peer}")
 
-    return peer
+    return _registered_peer


Code review comments:
diff_hunk: @@ -3,20 +3,27 @@
 
 DEFAULT_NETWORK_URL = "ws://ec2-13-59-45-128.us-east-2.compute.amazonaws.com"
 
+_registered_peer = None
+
 
 def register(**kwargs):
     """ Add this process as a new peer registering it in the grid network.
-        
+
         Returns:
             peer: Peer Network instance.
     """
-    if not kwargs:
-        args = args = {"max_size": None, "timeout": 444, "url": DEFAULT_NETWORK_URL}
-    else:
-        args = kwargs
+    global _registered_peer
 
-    peer_id = str(uuid.uuid4())
-    peer = Network(peer_id, **args)
-    peer.start()
+    if _registered_peer is None:
+        if not kwargs:
+            args = args = {"max_size": None, "timeout": 444, "url": DEFAULT_NETWORK_URL}
+        else:
+            args = kwargs
+
+        peer_id = str(uuid.uuid4())
+        _registered_peer = Network(peer_id, **args)
+        _registered_peer.start()
+    else:
+        raise UserWarning(f"You're already a registered peer {_registered_peer}")
path: syft/grid/__init__.py
text: @author:
I was wondering if there is a need to throw an warning/error in the user's face if he tries to register multiple times. I think just returning the registered peer for the first time would be okay.  What do you think?

@user1:
Yep, I think we can return the registered peer instance created by the first call. But we probably need to print a warning (not an exception or error message) to clarify to the user that they already have a registered peer.