Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted usages of Py_BEGIN_ALLOW_THREADS #124

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ Message Consumer_receive(Consumer& consumer) {

Message Consumer_receive_timeout(Consumer& consumer, int timeoutMs) {
Message msg;
Result res;
Py_BEGIN_ALLOW_THREADS res = consumer.receive(msg, timeoutMs);
Py_END_ALLOW_THREADS

CHECK_RESULT(res);
py::gil_scoped_release release;
CHECK_RESULT(consumer.receive(msg, timeoutMs));
return msg;
}

Messages Consumer_batch_receive(Consumer& consumer) {
Messages msgs;
Result res;
Py_BEGIN_ALLOW_THREADS res = consumer.batchReceive(msgs);
Py_END_ALLOW_THREADS CHECK_RESULT(res);

py::gil_scoped_release release;
CHECK_RESULT(consumer.batchReceive(msgs));
return msgs;
}

Expand All @@ -59,8 +57,8 @@ void Consumer_acknowledge_message_id(Consumer& consumer, const MessageId& msgId)
}

void Consumer_negative_acknowledge(Consumer& consumer, const Message& msg) {
Py_BEGIN_ALLOW_THREADS consumer.negativeAcknowledge(msg);
Py_END_ALLOW_THREADS
py::gil_scoped_release release;
consumer.negativeAcknowledge(msg);
}

void Consumer_negative_acknowledge_message_id(Consumer& consumer, const MessageId& msgId) {
Expand Down Expand Up @@ -97,11 +95,8 @@ bool Consumer_is_connected(Consumer& consumer) { return consumer.isConnected();

MessageId Consumer_get_last_message_id(Consumer& consumer) {
MessageId msgId;
Result res;
Py_BEGIN_ALLOW_THREADS res = consumer.getLastMessageId(msgId);
Py_END_ALLOW_THREADS

CHECK_RESULT(res);
py::gil_scoped_release release;
CHECK_RESULT(consumer.getLastMessageId(msgId));
return msgId;
}

Expand Down
6 changes: 3 additions & 3 deletions src/producer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ MessageId Producer_send(Producer& producer, const Message& message) {
}

void Producer_sendAsync(Producer& producer, const Message& msg, SendCallback callback) {
Py_BEGIN_ALLOW_THREADS producer.sendAsync(msg, callback);
Py_END_ALLOW_THREADS
py::gil_scoped_release release;
producer.sendAsync(msg, callback);

if (PyErr_CheckSignals() == -1) {
if (PyErr_CheckSignals() == -1) {
PyErr_SetInterrupt();
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ Message Reader_readNext(Reader& reader) {

Message Reader_readNextTimeout(Reader& reader, int timeoutMs) {
Message msg;
Result res;
Py_BEGIN_ALLOW_THREADS res = reader.readNext(msg, timeoutMs);
Py_END_ALLOW_THREADS
py::gil_scoped_release release;
CHECK_RESULT(reader.readNext(msg, timeoutMs));

CHECK_RESULT(res);
return msg;
}

Expand Down