BewareMyPower commented on code in PR #265:
URL: 
https://github.com/apache/pulsar-client-python/pull/265#discussion_r2197776001


##########
src/config.cc:
##########
@@ -104,6 +105,19 @@ class HIDDEN LoggerWrapperFactory : public LoggerFactory, 
public CaptivePythonOb
     }
 };
 
+using MessageRouterFunc = std::function<int(const Message&, int)>;
+class HIDDEN MessageRouter : public pulsar::MessageRoutingPolicy {
+   public:
+    explicit MessageRouter(MessageRouterFunc func) : func_(std::move(func)) {}
+
+    int getPartition(const Message& msg, const TopicMetadata& topicMetadata) 
final {
+        return func_(msg, topicMetadata.getNumPartitions());

Review Comment:
   https://pybind11.readthedocs.io/en/stable/advanced/misc.html
   
   > For example, if a Python callback is passed to C++ code via std::function, 
when C++ code calls the function the built-in wrapper will acquire the GIL 
before calling the Python callback.
   
   pybind11 guarantees GIL is held when executing the Python callback. 
https://github.com/pybind/pybind11/blob/4dc4aca2e120180e6bb48c076986feff41b4f5fb/include/pybind11/functional.h#L52



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to