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

ChunkyPNG::Canvas.from_file fails outside main Ractor #170

Open
TheHashTableSlasher opened this issue Dec 21, 2022 · 1 comment
Open

ChunkyPNG::Canvas.from_file fails outside main Ractor #170

TheHashTableSlasher opened this issue Dec 21, 2022 · 1 comment

Comments

@TheHashTableSlasher
Copy link

Trying to run the following code:

require 'chunky_png'

ractor = Ractor.new { ChunkyPNG::Canvas.from_file("some_image.png") }
img = ractor.take
# do something with img...

results in a Ractor::IsolationError saying that some constant is non-shareable. To work around this, I had to manually freeze any constants that were accessed by the call. These were the ones I had to freeze for this specific example (i.e. putting this code at the top allows the example to run):

ChunkyPNG::Chunk::CHUNK_TYPES.freeze
ChunkyPNG::EXTRA_BYTE.freeze

I haven't messed around with any of the other functions yet, so I'm sure there are other non-frozen constants in the library that may need to be frozen to allow some methods to work with Ractors.

@TheHashTableSlasher
Copy link
Author

TheHashTableSlasher commented Dec 22, 2022

I just learned about the shareable_constant_value pragma, which would pretty much perform the same thing as my pull request. Use that instead, if you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant