WEBVTT

1
00:00:01.640 --> 00:00:03.000
<v ->Hi guys, and welcome back.</v>

2
00:00:03.000 --> 00:00:04.600
In this quick video, I just wanted to tell you

3
00:00:04.600 --> 00:00:08.740
about thread and process safety in psycopg2

4
00:00:08.740 --> 00:00:11.700
and also how you can use async and await

5
00:00:11.700 --> 00:00:14.610
with PostgreSQL, in case you're interested in doing that.

6
00:00:14.610 --> 00:00:18.030
So first of all, psycopg2 is thread-safe,

7
00:00:18.030 --> 00:00:21.750
but it doesn't support asynchronous out-of-the-box.

8
00:00:21.750 --> 00:00:25.220
So you can't use things like async and await directly.

9
00:00:25.220 --> 00:00:29.700
You can use the SELECT module in order to essentially pull

10
00:00:29.700 --> 00:00:33.680
the database or let the database tell you when you're ready

11
00:00:33.680 --> 00:00:37.940
to receive or send information to Postgres,

12
00:00:37.940 --> 00:00:39.340
but it's a bit clunky.

13
00:00:39.340 --> 00:00:41.930
So the official documentation has a guide on how to do that,

14
00:00:41.930 --> 00:00:43.150
essentially, and I'm gonna link it

15
00:00:43.150 --> 00:00:45.350
in the resources section of this lecture.

16
00:00:45.350 --> 00:00:48.480
But it's not ideal, I wouldn't use it.

17
00:00:48.480 --> 00:00:51.680
So instead, if you want to use async and await

18
00:00:51.680 --> 00:00:54.880
for asynchronous development with Postgres

19
00:00:54.880 --> 00:00:57.370
so that you can use, for example, in event loop

20
00:00:57.370 --> 00:01:01.200
using Postgres, you can use a AIOPG,

21
00:01:01.200 --> 00:01:04.650
which stands for async IO, PostgreSQL.

22
00:01:04.650 --> 00:01:06.970
So if you want to do that, please have a look

23
00:01:06.970 --> 00:01:10.700
at the AIOPG website, it has a lot of information.

24
00:01:10.700 --> 00:01:13.630
Overall, it's pretty similar to psycopg2, indeed.

25
00:01:13.630 --> 00:01:17.250
It uses psycopg2 behind the scenes, but it does add support

26
00:01:17.250 --> 00:01:20.090
for async and await a bit more easily without having to use

27
00:01:20.090 --> 00:01:21.730
the SELECT module.

28
00:01:21.730 --> 00:01:23.540
So I'm gonna leave that link in the resources section

29
00:01:23.540 --> 00:01:24.373
of this video.

30
00:01:24.373 --> 00:01:27.160
If you want to take a look at that, then please do,

31
00:01:27.160 --> 00:01:30.470
and if not, just remember that it is possible to use async

32
00:01:30.470 --> 00:01:33.960
and await with Postgres with AIOPG, in case you need

33
00:01:33.960 --> 00:01:34.870
that later on.

34
00:01:34.870 --> 00:01:36.580
All right, thank you guys for joining me in this video.

35
00:01:36.580 --> 00:01:38.030
I'll see you in the next one.

