You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
</span><spanclass="n">cur</span><spanclass="o">.</span><spanclass="n">execute</span><spanclass="p">(</span><spanclass="n">SQL</span><spanclass="p">,</span><spanclass="p">(</span><spanclass="n">arg1</span><spanclass="p">,</span><spanclass="n">arg2</span><spanclass="p">))</span><spanclass="c1"># or something else</span><spanclass="w">
86
86
@@ -95,8 +95,8 @@ <h1>Passing connections to functions using a decorator</h1>
95
95
</ul>
96
96
<p>Implementation of such a decorator is straightforward, but because of the many possible variation it never made its way into a proper library. It goes something like:</p>
</span><spanclass="n">cur</span><spanclass="o">.</span><spanclass="n">execute</span><spanclass="p">(</span><spanclass="n">SQL</span><spanclass="p">,</span><spanclass="p">(</span><spanclass="n">arg1</span><spanclass="p">,</span><spanclass="n">arg2</span><spanclass="p">))</span><spanclass="c1"># or something else</span><spanclass="w">
Copy file name to clipboardExpand all lines: articles/2010/12/01/postgresql-notifications-psycopg2-eventlet/index.html
+8-8
Original file line number
Diff line number
Diff line change
@@ -92,12 +92,12 @@ <h2>Eventlet example</h2>
92
92
<p>This example shows how hook the notifications system into Eventlet: using it with a <aclass="reference external" href="https://en.wikipedia.org/wiki/WebSockets">WebSocket</a> it is possible to send an event from the database to the application and up to a web browser, all in push mode! The example requires PostgreSQL 9.0 and Psycopg 2.3 as it uses notification payloads.</p>
93
93
<p>This function handles a WebSocket connection in a green thread: it creates a <ttclass="docutils literal">Queue</tt> and opens a database connection (calling the <ttclass="docutils literal">dblisten()</tt> function), then blocks on the queue waiting to receive notifications: as soon as any is received, its payload is forwarded to the browser. This is obviously just an example: a database connection for every browser wouldn't scale very much...</p>
Receive a connection and send it database notifications.
103
103
"""</span><spanclass="w">
@@ -111,11 +111,11 @@ <h2>Eventlet example</h2>
111
111
<p>When <ttclass="docutils literal">handle()</tt> blocks on the queue the control of the program switches to a different green thread, allowing the rest of the program to keep on running even if single-threaded.</p>
112
112
<p>The <ttclass="docutils literal">dblisten</tt> function sets up the listening database connection:</p>
<p>a much handier syntax for an often used connection property.</p>
101
101
<p>The improvements to the transactions control are not only at interface level: Psycopg doesn't require any more setup queries when connecting to a database. A sequence of statements:</p>
Copy file name to clipboardExpand all lines: articles/2014/07/20/cancelling-postgresql-statements-python/index.html
+3-3
Original file line number
Diff line number
Diff line change
@@ -81,10 +81,10 @@ <h1>Cancelling PostgreSQL statements from Python</h1>
81
81
<!-- CUT-HERE -->
82
82
<p>Using psycopg in <aclass="reference external" href="/docs/advanced.html#support-for-coroutine-libraries">green mode</a> moves the waiting from the libpq C code to Python: this gives Python some chance of interaction: it is possible for instance to catch a ctrl-c and send a cancel request:</p>
0 commit comments