Skip to content

Callbacks to Ruby from the Python side #192

@Tennesseej

Description

@Tennesseej

First off, thank you for the fantastic Gem, it's been a lifesaver for a project I've been working on (and your notes in the README about PyGILState_Ensure and PyGILState_Release helped me make it work in a Threaded scenario I have!).

I have a question about callbacks to Ruby code from the Python side.

Specifically from my main Ruby program I am calling some Python code that runs indefinitely, and then when events happen on the Python side I want to trigger some other Ruby code to run.

Unfortunately it's not trivial to setup an example (which also prevents running the Ruby code as a subprocess or something on the Python side), but the best way to describe it I can think of is this:

  1. Start a Ruby program
  2. Call a Python program that draws a GUI via PyCall
  3. User Clicks on a button in the GUI
  4. The Click triggers a block of Ruby code to run

The only thing I can think of right now is either constantly polling the Python side for some state in a Thread on the Ruby side (not my favorite), or setting up something like ZeroMQ and have the Python side push messages that are consumed on the Ruby side when the interaction occurs, but before I go down that path I wanted to make sure I wasn't missing something easy regarding PyCall callbacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions