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

To fix an issue that a library/executable script needs to run the eventloop other than the main thread only when it is executed as a command. #49

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

h-nagai
Copy link
Contributor

@h-nagai h-nagai commented Oct 23, 2022

When a executable Tk library script, e.g. "sample/tktextio.rb", is executed as a command, it may need to run the eventloop other than the main thread. However, when loaded as a library, it should not force the running-mode of the eventloop. "thread_tk.rb" is one solution to the problem by writing a sh-bang line like "#!/usr/bin/ruby -r thread_tk".

fix that sample/irbtkw.rbw doesn't work with the recent IRB

is executed as a command, it may need to run the eventloop other
than the main thread. However, when loaded as a library, it
should not force the running-mode of the eventloop. "thread_tk.rb"
is one solution to the problem by writing a sh-bang line like
"#!/usr/bin/ruby -r thread_tk".

fix that sample/irbtkw.rbw doesn't work with the recent IRB
Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. I'm guessing this wasn't an issue until we made the event loop run on the main thread by default for performance reasons.

@h-nagai
Copy link
Contributor Author

h-nagai commented Oct 24, 2022

In thread_tk.rb, it is better to raise an exception if tk.rb is already loaded.
For example, add the followings at top of thread_tk.rb.
if $LOADED_FEATURES.find{|path| path =~ %r!/tk.rb$!}
raise LoadError, "thread_tk.rb must be loaded before tk.rb
end

@jeremyevans
Copy link
Contributor

@h-nagai I added #53 to implement the check you requested. Instead of checking $LOADED_FEATURES, it checks to see whether the constant has already been set to true.

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

Successfully merging this pull request may close these issues.

2 participants