all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: 813gan <813gan@protonmail.com>
To: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Threads vs url-http
Date: Sun, 29 Sep 2024 00:28:36 +0000	[thread overview]
Message-ID: <3GKP9PAUIwZh8IYYiDahnaeVDrY2O7V_LkjMJ_EcOfSz0ltAUheLQ47o9l8VIm0-8vGVQpKuFMjq2qLiHVN3BIeLKx_AbaacMBQbfvR9_cs=@protonmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

Hi.
I attempted to write thread-friendly wrapper around url-http and it appears to hang Emacs.
Am i doing something wrong or it's bug?

(require 'url-http)
(require 'url-parse)
(defun url-retrieve-thread (url)
"Wrapper around url-http that download `URL' without blocking main thread."
(let* ((parsed-url (if (url-p url) url (url-generic-parse-url url)))
(mut (make-mutex))
(cond-var (make-condition-variable mut))
(buf nil)
(cb (lambda (&rest _) (setq buf (current-buffer)) (with-mutex mut (condition-notify cond-var)) )) )
(url-http parsed-url cb nil)
(with-mutex mut
(condition-wait cond-var) )
buf))

Idea was to call it from thread. In most trivial case:
(make-thread (apply 'url-retrieve-thread "http://example.com" nil))

It makes Emacs unresponsive (even C-g does not work).
I tested it on Emacs 28.2 and once of recent development versions (emacs-31.0.50)

Happy Hacking!

[-- Attachment #2: Type: text/html, Size: 2090 bytes --]

             reply	other threads:[~2024-09-29  0:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-29  0:28 813gan [this message]
2024-09-29  5:26 ` Threads vs url-http Eli Zaretskii
2024-09-29 23:53   ` 813gan
2024-09-30  7:38     ` Michael Albinus
2024-09-30 12:22     ` Eli Zaretskii
2024-10-06 15:06       ` 813gan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='3GKP9PAUIwZh8IYYiDahnaeVDrY2O7V_LkjMJ_EcOfSz0ltAUheLQ47o9l8VIm0-8vGVQpKuFMjq2qLiHVN3BIeLKx_AbaacMBQbfvR9_cs=@protonmail.com' \
    --to=813gan@protonmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.