Commit b883f42
committed
Wrap the interruption to a custom exception when a blocking API is interrupted (#99)
### Motivation
Currently, when a blocking API is interrupted by a signal, `SystemError`
will be thrown. However, in this case, `PyErr_SetInterrupt` will be
called and next time a blocking API is called, `std::system_error` will
be somehow thrown.
The failure of
https://lists.apache.org/thread/cmzykd9qz9x1d0s35nc5912o3slwpxpv is
caused by this issue. The `SystemError` is not called, then
`client.close()` will be skipped, which leads to the `bad_weak_ptr`
error.
P.S. Currently we have to call `client.close()` on a `Client` instance,
otherwise, the `bad_weak_ptr` will be thrown.
However, even if we caught the `SystemError` like:
```python
try:
msg = consumer.receive()
# ...
except SystemError:
break
```
we would still see the following error:
```
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted
```
### Modifications
- Wrap `ResultInterrupted` into the `pulsar.Interrupted` exception.
- Refactor the `waitForAsyncValue` and `waitForAsyncResult` functions
and raise `pulsar.Interrupted` when `PyErr_CheckSignals` detects a
signal.
- Add `InterruptedTest` to cover this case.
- Remove `future.h` since we now use `std::future` instead of the
manually implemented `Future`.
- Fix the `examples/consumer.py` to support stopping by Ctrl+C.
(cherry picked from commit ec05f50)1 parent 9ed92ec commit b883f42
File tree
11 files changed
+121
-331
lines changed- examples
- pulsar
- src
- tests
11 files changed
+121
-331
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 27 | + | |
| 28 | + | |
35 | 29 | | |
36 | 30 | | |
37 | 31 | | |
38 | 32 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 33 | + | |
| 34 | + | |
47 | 35 | | |
48 | 36 | | |
49 | 37 | | |
50 | 38 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 39 | + | |
| 40 | + | |
59 | 41 | | |
60 | 42 | | |
61 | 43 | | |
62 | 44 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
71 | 48 | | |
72 | 49 | | |
73 | 50 | | |
74 | 51 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 52 | + | |
| 53 | + | |
83 | 54 | | |
84 | 55 | | |
85 | 56 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 57 | + | |
| 58 | + | |
94 | 59 | | |
95 | 60 | | |
96 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 32 | + | |
39 | 33 | | |
40 | 34 | | |
41 | 35 | | |
| |||
59 | 53 | | |
60 | 54 | | |
61 | 55 | | |
62 | | - | |
63 | | - | |
| 56 | + | |
64 | 57 | | |
65 | 58 | | |
66 | 59 | | |
67 | 60 | | |
68 | | - | |
69 | | - | |
| 61 | + | |
70 | 62 | | |
71 | 63 | | |
72 | 64 | | |
73 | 65 | | |
74 | | - | |
75 | | - | |
| 66 | + | |
76 | 67 | | |
77 | 68 | | |
78 | 69 | | |
79 | 70 | | |
80 | | - | |
81 | | - | |
| 71 | + | |
82 | 72 | | |
83 | 73 | | |
84 | 74 | | |
85 | 75 | | |
86 | | - | |
87 | | - | |
| 76 | + | |
88 | 77 | | |
89 | 78 | | |
90 | 79 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 28 | + | |
| 29 | + | |
35 | 30 | | |
36 | 31 | | |
37 | 32 | | |
38 | | - | |
39 | | - | |
| 33 | + | |
40 | 34 | | |
41 | 35 | | |
42 | | - | |
| 36 | + | |
43 | 37 | | |
44 | 38 | | |
45 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 65 | + | |
| 66 | + | |
73 | 67 | | |
74 | 68 | | |
75 | 69 | | |
| |||
0 commit comments