* Asynchronously downloading a file
@ 2010-07-01 21:43 Deniz Dogan
2010-07-02 6:33 ` Qiang Guo
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Deniz Dogan @ 2010-07-01 21:43 UTC (permalink / raw)
To: help-gnu-emacs
I'm currently using find-file to view images fetched over HTTP.
However, sometimes the server hosting the image is kind of slow and
thus Emacs just hangs waiting for the image to fully download before I
can view it.
Is there any existing Emacs functionality which asynchronously gets a
file from any of the protocols that e.g. find-file (tramp?) supports
which lets me provide a callback function?
Thanks,
Deniz Dogan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-01 21:43 Asynchronously downloading a file Deniz Dogan
@ 2010-07-02 6:33 ` Qiang Guo
2010-07-02 9:04 ` Deniz Dogan
2010-07-02 9:06 ` Daniel Pittman
2010-07-02 7:41 ` David Engster
` (2 subsequent siblings)
3 siblings, 2 replies; 11+ messages in thread
From: Qiang Guo @ 2010-07-02 6:33 UTC (permalink / raw)
To: Deniz Dogan; +Cc: help-gnu-emacs
Emacs adheres to single thread fervently, so it may be
impossible to do this within emacs.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-01 21:43 Asynchronously downloading a file Deniz Dogan
2010-07-02 6:33 ` Qiang Guo
@ 2010-07-02 7:41 ` David Engster
2010-07-02 9:23 ` Alberto Luaces
[not found] ` <mailman.5.1278062489.22038.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 11+ messages in thread
From: David Engster @ 2010-07-02 7:41 UTC (permalink / raw)
To: help-gnu-emacs
Deniz Dogan writes:
> I'm currently using find-file to view images fetched over HTTP.
> However, sometimes the server hosting the image is kind of slow and
> thus Emacs just hangs waiting for the image to fully download before I
> can view it.
>
> Is there any existing Emacs functionality which asynchronously gets a
> file from any of the protocols that e.g. find-file (tramp?) supports
> which lets me provide a callback function?
I don't think there's something in Emacs proper which does that right
away.
At least for http, you could use emacs-w3m, which support asynchronous
retrieval of URLs:
(w3m-retrieve URL &optional NO-UNCOMPRESS NO-CACHE POST-DATA REFERER
HANDLER)
Retrieve web contents pointed to by URL.
It will put the retrieved contents into the current buffer.
[...]
If HANDLER is a function, this function will come to an end in no time.
In this case, contents will be retrieved by the asynchronous process
after a while. And after finishing retrieving contents successfully,
HANDLER will be called on the buffer where this function starts.
[...]
Regards,
David
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-02 6:33 ` Qiang Guo
@ 2010-07-02 9:04 ` Deniz Dogan
2010-07-02 9:06 ` Daniel Pittman
1 sibling, 0 replies; 11+ messages in thread
From: Deniz Dogan @ 2010-07-02 9:04 UTC (permalink / raw)
To: Qiang Guo; +Cc: help-gnu-emacs
2010/7/2 Qiang Guo <mcknight0219@gmail.com>:
>
> Emacs adheres to single thread fervently, so it may be
> impossible to do this within emacs.
>
I was not necessarily looking for threading, but just spawning a
process, e.g. wget, which gets the file for me. :)
--
Deniz Dogan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-02 6:33 ` Qiang Guo
2010-07-02 9:04 ` Deniz Dogan
@ 2010-07-02 9:06 ` Daniel Pittman
2010-07-02 9:22 ` Deniz Dogan
1 sibling, 1 reply; 11+ messages in thread
From: Daniel Pittman @ 2010-07-02 9:06 UTC (permalink / raw)
To: help-gnu-emacs
Qiang Guo <mcknight0219@gmail.com> writes:
> Emacs adheres to single thread fervently, so it may be impossible to do this
> within emacs.
That isn't actually all that true: while there is only a single thread of
execution within Emacs you can address this in one of two ways:
The obvious, and sane, way is to take advantage of the event-driven I/O
functionality present in Emacs as part of the process / network-connection
filter infrastructure.
In this mode you tell the system to start the download, then your function is
called (or data collected in a buffer) as it is available to be read. While
there is only a single thread, this will jump over to handling your download
transparently to doing other activities.
The second way is to use an external process to do the same; you can even
invoke 'emacs --batch --eval' if you really want to. :)
Daniel
The second way is kind of wasteful given that `open-network-stream' is
actually entirely asynchronous and all.
--
✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-02 9:06 ` Daniel Pittman
@ 2010-07-02 9:22 ` Deniz Dogan
2010-07-02 9:46 ` Daniel Pittman
0 siblings, 1 reply; 11+ messages in thread
From: Deniz Dogan @ 2010-07-02 9:22 UTC (permalink / raw)
To: Daniel Pittman; +Cc: help-gnu-emacs
2010/7/2 Daniel Pittman <daniel@rimspace.net>:
> Qiang Guo <mcknight0219@gmail.com> writes:
>
>> Emacs adheres to single thread fervently, so it may be impossible to do this
>> within emacs.
>
> [snip]
>
> The second way is to use an external process to do the same; you can even
> invoke 'emacs --batch --eval' if you really want to. :)
>
> Daniel
>
> The second way is kind of wasteful given that `open-network-stream' is
> actually entirely asynchronous and all.
>
I'm looking for something like that, but with some layer taking care
of the HTTP stuff for me. I am specifically looking for something
which lets me make a GET or POST request and easily extract the
response body. Error handling such as 404, 500, etc. would be nice as
well.
--
Deniz Dogan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-01 21:43 Asynchronously downloading a file Deniz Dogan
2010-07-02 6:33 ` Qiang Guo
2010-07-02 7:41 ` David Engster
@ 2010-07-02 9:23 ` Alberto Luaces
[not found] ` <mailman.5.1278062489.22038.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 11+ messages in thread
From: Alberto Luaces @ 2010-07-02 9:23 UTC (permalink / raw)
To: help-gnu-emacs
Deniz Dogan writes:
> Is there any existing Emacs functionality which asynchronously gets a
> file from any of the protocols that e.g. find-file (tramp?) supports
> which lets me provide a callback function?
Asynchronously, you could take a look at try wget-el. I'm not sure about
the callback part, though.
--
Alberto
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
[not found] ` <mailman.5.1278062489.22038.help-gnu-emacs@gnu.org>
@ 2010-07-02 9:24 ` Andreas Politz
0 siblings, 0 replies; 11+ messages in thread
From: Andreas Politz @ 2010-07-02 9:24 UTC (permalink / raw)
To: help-gnu-emacs
Alberto Luaces <aluaces@udc.es> writes:
> Deniz Dogan writes:
>
>> Is there any existing Emacs functionality which asynchronously gets a
>> file from any of the protocols that e.g. find-file (tramp?) supports
>> which lets me provide a callback function?
>
> Asynchronously, you could take a look at try wget-el. I'm not sure about
> the callback part, though.
There is also `url-retrieve'.
-ap
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-02 9:22 ` Deniz Dogan
@ 2010-07-02 9:46 ` Daniel Pittman
2010-07-02 10:11 ` Deniz Dogan
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Pittman @ 2010-07-02 9:46 UTC (permalink / raw)
To: help-gnu-emacs
Deniz Dogan <deniz.a.m.dogan@gmail.com> writes:
> 2010/7/2 Daniel Pittman <daniel@rimspace.net>:
>> Qiang Guo <mcknight0219@gmail.com> writes:
>>
>>> Emacs adheres to single thread fervently, so it may be impossible to do this
>>> within emacs.
>>
>> [snip]
>>
>> The second way is to use an external process to do the same; you can even
>> invoke 'emacs --batch --eval' if you really want to. :)
>>
>> Daniel
>>
>> The second way is kind of wasteful given that `open-network-stream' is
>> actually entirely asynchronous and all.
>
> I'm looking for something like that, but with some layer taking care of the
> HTTP stuff for me.
Oh. You mean `url-retrieve'.
Daniel
--
✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707
♽ made with 100 percent post-consumer electrons
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-02 9:46 ` Daniel Pittman
@ 2010-07-02 10:11 ` Deniz Dogan
2010-07-02 10:16 ` Lennart Borgman
0 siblings, 1 reply; 11+ messages in thread
From: Deniz Dogan @ 2010-07-02 10:11 UTC (permalink / raw)
To: Daniel Pittman; +Cc: help-gnu-emacs
2010/7/2 Daniel Pittman <daniel@rimspace.net>:
> Deniz Dogan <deniz.a.m.dogan@gmail.com> writes:
>> 2010/7/2 Daniel Pittman <daniel@rimspace.net>:
>>> Qiang Guo <mcknight0219@gmail.com> writes:
>>>
>>>> Emacs adheres to single thread fervently, so it may be impossible to do this
>>>> within emacs.
>>>
>>> [snip]
>>>
>>> The second way is to use an external process to do the same; you can even
>>> invoke 'emacs --batch --eval' if you really want to. :)
>>>
>>> Daniel
>>>
>>> The second way is kind of wasteful given that `open-network-stream' is
>>> actually entirely asynchronous and all.
>>
>> I'm looking for something like that, but with some layer taking care of the
>> HTTP stuff for me.
>
> Oh. You mean `url-retrieve'.
>
That looks very interesting. Thank you.
--
Deniz Dogan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Asynchronously downloading a file
2010-07-02 10:11 ` Deniz Dogan
@ 2010-07-02 10:16 ` Lennart Borgman
0 siblings, 0 replies; 11+ messages in thread
From: Lennart Borgman @ 2010-07-02 10:16 UTC (permalink / raw)
To: Deniz Dogan; +Cc: Daniel Pittman, help-gnu-emacs
On Fri, Jul 2, 2010 at 12:11 PM, Deniz Dogan <deniz.a.m.dogan@gmail.com> wrote:
>>
>> Oh. You mean `url-retrieve'.
>>
>
> That looks very interesting. Thank you.
There is code using this in pause.el in nXhtml if you want an example.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-07-02 10:16 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-01 21:43 Asynchronously downloading a file Deniz Dogan
2010-07-02 6:33 ` Qiang Guo
2010-07-02 9:04 ` Deniz Dogan
2010-07-02 9:06 ` Daniel Pittman
2010-07-02 9:22 ` Deniz Dogan
2010-07-02 9:46 ` Daniel Pittman
2010-07-02 10:11 ` Deniz Dogan
2010-07-02 10:16 ` Lennart Borgman
2010-07-02 7:41 ` David Engster
2010-07-02 9:23 ` Alberto Luaces
[not found] ` <mailman.5.1278062489.22038.help-gnu-emacs@gnu.org>
2010-07-02 9:24 ` Andreas Politz
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.