-
Notifications
You must be signed in to change notification settings - Fork 73
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
Respond to signals when outside the GIL #150
Comments
When calling So what does your unblock function need to do? There are a couple of methods (which I haven't tested, but should work), all of which need changes beyond just writing an unblock function. First, there is The other alternative is to have an actual event loop (maybe using libev or libevent, or possibly one written by yourself) and integrate libcurl into that event loop. Your unblock function then simply cancels the event loop using whatever mechanism is appropriate for your event loop implementation. The mechanism in libcurl that allows event loop integration is libcurl-multi. |
@FooBarWidget thanks for your explanation! The plot thickens since I found something peculiar. I did indeed experiment with a custom ubf. If I take an implementation like this:
and run a test case like this:
then I am able to use Ctrl+C to abort. I also do see that the unblock fun gets called (that's why the prinft). The interrupt gets set for libCURL and libCURL then aborts in it's progress callback function - all is nice and dandy. Doing a thread kill also works:
I do get feedback on the terminal that the UBF did get triggered.
The progress callback function we set for libCURL is getting called still, so that's fine - but Ruby never calls the UBF. So whichever solution I choose from what you have outlined I don't understand how to receive the signal in the first place when I have multiple threads running :-( |
A Ctrl-C only kills the main thread. If you want any other threads to be killed as well then you need to propagate that signal to those threads manually. |
Currently Patron unlocks the GIL while performing the curl call. This is really good for enabling true parallelism, but Ruby does not trap signals when a Patron call is in progress. Signals also do not get delivered once the curl call completes. This can be problematic if an application performing a long Patron call has to be stopped or restarted -
kill -9
is pretty much the only option to deal with this, and it's really not very gentle. At least for the basic set of signals (SIGINT
,SIGTERM
) Patron should provide a way to bail out of the curl call and yield control back to Ruby. This has to be done either with an unblock function or by installing custom interrupt handlers within the patron call, obviously with care to tear them down later.The text was updated successfully, but these errors were encountered: