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