Terminate the copy operation and free the resources allocated. You shouldn't need to call this function yourself: it is usually called by exit. It is available if, despite what is documented, you end up using the `Copy` object outside a block.
(self, exc: BaseException | None)
| 129 | self._write(data) |
| 130 | |
| 131 | def finish(self, exc: BaseException | None) -> None: |
| 132 | """Terminate the copy operation and free the resources allocated. |
| 133 | |
| 134 | You shouldn't need to call this function yourself: it is usually called |
| 135 | by exit. It is available if, despite what is documented, you end up |
| 136 | using the `Copy` object outside a block. |
| 137 | """ |
| 138 | if self._direction == COPY_IN: |
| 139 | if not exc: |
| 140 | if data := self.formatter.end(): |
| 141 | self._write(data) |
| 142 | self.writer.finish(exc) |
| 143 | self._finished = True |
| 144 | else: |
| 145 | if not exc: |
| 146 | return |
| 147 | if self._pgconn.transaction_status != ACTIVE: |
| 148 | # The server has already finished to send copy data. The connection |
| 149 | # is already in a good state. |
| 150 | return |
| 151 | # Throw a cancel to the server, then consume the rest of the copy data |
| 152 | # (which might or might not have been already transferred entirely to |
| 153 | # the client, so we won't necessary see the exception associated with |
| 154 | # canceling). |
| 155 | self.connection._try_cancel() |
| 156 | self.connection.wait(self._end_copy_out_gen()) |
| 157 | |
| 158 | |
| 159 | class Writer(ABC): |