MCPcopy Index your code
hub / github.com/python/cpython / testShare

Method testShare

Lib/test/test_socket.py:6726–6759  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

6724 s.close()
6725
6726 def testShare(self):
6727 # Transfer the listening server socket to another process
6728 # and service it from there.
6729
6730 # Create process:
6731 q = multiprocessing.Queue()
6732 p = multiprocessing.Process(target=self.remoteProcessServer, args=(q,))
6733 p.start()
6734
6735 # Get the shared socket data
6736 data = self.serv.share(p.pid)
6737
6738 # Pass the shared socket to the other process
6739 addr = self.serv.getsockname()
6740 self.serv.close()
6741 q.put(data)
6742
6743 # The data that the server will send us
6744 message = b"slapmahfro"
6745 q.put(message)
6746
6747 # Connect
6748 s = socket.create_connection(addr)
6749 # listen for the data
6750 m = []
6751 while True:
6752 data = s.recv(100)
6753 if not data:
6754 break
6755 m.append(data)
6756 s.close()
6757 received = b"".join(m)
6758 self.assertEqual(received, message)
6759 p.join()
6760
6761 def testShareLength(self):
6762 data = self.serv.share(os.getpid())

Callers

nothing calls this directly

Calls 11

putMethod · 0.95
QueueMethod · 0.80
ProcessMethod · 0.45
startMethod · 0.45
getsocknameMethod · 0.45
closeMethod · 0.45
create_connectionMethod · 0.45
recvMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected