| 433 | main_thread = threading.get_ident() |
| 434 | |
| 435 | def run_client(): |
| 436 | s = socket.socket(server.address_family, socket.SOCK_STREAM, |
| 437 | socket.IPPROTO_TCP) |
| 438 | with s, s.makefile('rb') as reader: |
| 439 | s.connect(server.server_address) |
| 440 | nonlocal response1 |
| 441 | response1 = reader.readline() |
| 442 | s.sendall(b'client response\n') |
| 443 | |
| 444 | reader.read(100) |
| 445 | # The main thread should now be blocking in a send() syscall. |
| 446 | # But in theory, it could get interrupted by other signals, |
| 447 | # and then retried. So keep sending the signal in a loop, in |
| 448 | # case an earlier signal happens to be delivered at an |
| 449 | # inconvenient moment. |
| 450 | while True: |
| 451 | pthread_kill(main_thread, signal.SIGUSR1) |
| 452 | if interrupted.wait(timeout=float(1)): |
| 453 | break |
| 454 | nonlocal received2 |
| 455 | received2 = len(reader.read()) |
| 456 | |
| 457 | background = threading.Thread(target=run_client) |
| 458 | background.start() |