MCPcopy Index your code
hub / github.com/RustPython/RustPython / testShare

Method testShare

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

Source from the content-addressed store, hash-verified

6621 s.close()
6622
6623 def testShare(self):
6624 # Transfer the listening server socket to another process
6625 # and service it from there.
6626
6627 # Create process:
6628 q = multiprocessing.Queue()
6629 p = multiprocessing.Process(target=self.remoteProcessServer, args=(q,))
6630 p.start()
6631
6632 # Get the shared socket data
6633 data = self.serv.share(p.pid)
6634
6635 # Pass the shared socket to the other process
6636 addr = self.serv.getsockname()
6637 self.serv.close()
6638 q.put(data)
6639
6640 # The data that the server will send us
6641 message = b"slapmahfro"
6642 q.put(message)
6643
6644 # Connect
6645 s = socket.create_connection(addr)
6646 # listen for the data
6647 m = []
6648 while True:
6649 data = s.recv(100)
6650 if not data:
6651 break
6652 m.append(data)
6653 s.close()
6654 received = b"".join(m)
6655 self.assertEqual(received, message)
6656 p.join()
6657
6658 def testShareLength(self):
6659 data = self.serv.share(os.getpid())

Callers

nothing calls this directly

Calls 12

putMethod · 0.95
QueueMethod · 0.80
shareMethod · 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