MCPcopy
hub / github.com/psycopg/psycopg / finish

Method finish

psycopg/psycopg/_copy.py:131–156  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
159class Writer(ABC):

Callers 15

__exit__Method · 0.95
pgconnFunction · 0.45
test_wait_badFunction · 0.45
test_wait_large_fdFunction · 0.45
closerFunction · 0.45
closerFunction · 0.45
test_wait_badFunction · 0.45
test_wait_large_fdFunction · 0.45
closerFunction · 0.45
test_connect_asyncFunction · 0.45
test_finishFunction · 0.45
test_weakrefFunction · 0.45

Calls 4

_end_copy_out_genMethod · 0.80
endMethod · 0.45
_try_cancelMethod · 0.45
waitMethod · 0.45

Tested by 15

test_wait_badFunction · 0.36
test_wait_large_fdFunction · 0.36
closerFunction · 0.36
closerFunction · 0.36
test_wait_badFunction · 0.36
test_wait_large_fdFunction · 0.36
closerFunction · 0.36
test_connect_asyncFunction · 0.36
test_finishFunction · 0.36
test_weakrefFunction · 0.36
test_pgconn_ptrFunction · 0.36
test_infoFunction · 0.36