Buy commercial curl support from WolfSSL. We help you work
out your issues, debug your libcurl applications, use the API, port to new
platforms, add new features and more. With a team lead by the curl founder
himself.
Re: Making Python Script Exit Completely with One Ctrl+C
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Hongyi Zhao via curl-users <curl-users_at_lists.haxx.se>
Date: Sun, 10 Dec 2023 14:44:04 +0800
On Sun, Dec 10, 2023 at 1:47 PM Dan Fandrich via curl-users
<curl-users_at_lists.haxx.se> wrote:
>
> On Sun, Dec 10, 2023 at 12:35:16PM +0800, Hongyi Zhao via curl-users wrote:
> > But I still cannot figure out how to achieve the same purpose with the
> > following methods:
> >
> > 1. Using the following method suggested by you:
> >
> > You'll probably have to block SIGINT before calling calling into pycurl, then
> > unblocking in the progress callback to check it, e.g.
> [...]
> > 2. Using a pure try-expect-based method.
>
> What do you mean "pure try-expect-based method"? You mean without touching
> signal masks?
I mean without importing/relying on the signal module.
> As long as you're calling non-Python based C libraries, you're
> out of the realm of pure Python. If PyCurl were instead 100% Python, the
> KeyboardInterrupt would be raised as you expect and you could catch it
> normally. But in this case, not only is the interrupt happening while running
> C code, it's happening while running C code from Python while calling back to C
> code that in turn is calling code in Python. Handling that as this code now is
> in pure Python without having to drop to writing a C extension seems pretty
> good to me.
Do you mean the code implementation I've already posted here based on your tips?
> The alternative SIGINT handler solution should also work and may
> be more elegant, depending on your point of view.
I've already used the following code snippet:
def sigint_handler(signal, frame):
print(f"KeyboardInterrupt at line {frame.f_lineno}")
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
So, I don't understand why you still like the above.
> In any case, the issue has turned out to be unrelated to the topic of this
> list, so you're better off finding a PyCurl forum if you prefer another
> solution.
>
> Dan
Zhao
> --
> Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
> Etiquette: https://curl.se/mail/etiquette.html
Date: Sun, 10 Dec 2023 14:44:04 +0800
On Sun, Dec 10, 2023 at 1:47 PM Dan Fandrich via curl-users
<curl-users_at_lists.haxx.se> wrote:
>
> On Sun, Dec 10, 2023 at 12:35:16PM +0800, Hongyi Zhao via curl-users wrote:
> > But I still cannot figure out how to achieve the same purpose with the
> > following methods:
> >
> > 1. Using the following method suggested by you:
> >
> > You'll probably have to block SIGINT before calling calling into pycurl, then
> > unblocking in the progress callback to check it, e.g.
> [...]
> > 2. Using a pure try-expect-based method.
>
> What do you mean "pure try-expect-based method"? You mean without touching
> signal masks?
I mean without importing/relying on the signal module.
> As long as you're calling non-Python based C libraries, you're
> out of the realm of pure Python. If PyCurl were instead 100% Python, the
> KeyboardInterrupt would be raised as you expect and you could catch it
> normally. But in this case, not only is the interrupt happening while running
> C code, it's happening while running C code from Python while calling back to C
> code that in turn is calling code in Python. Handling that as this code now is
> in pure Python without having to drop to writing a C extension seems pretty
> good to me.
Do you mean the code implementation I've already posted here based on your tips?
> The alternative SIGINT handler solution should also work and may
> be more elegant, depending on your point of view.
I've already used the following code snippet:
def sigint_handler(signal, frame):
print(f"KeyboardInterrupt at line {frame.f_lineno}")
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
So, I don't understand why you still like the above.
> In any case, the issue has turned out to be unrelated to the topic of this
> list, so you're better off finding a PyCurl forum if you prefer another
> solution.
>
> Dan
Zhao
> --
> Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
> Etiquette: https://curl.se/mail/etiquette.html
-- Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users Etiquette: https://curl.se/mail/etiquette.htmlReceived on 2023-12-10