From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: yyoncho Newsgroups: gmane.emacs.devel Subject: Re: Questions about throw-on-input Date: Fri, 8 May 2020 14:55:16 +0300 Message-ID: References: <87r1vwxktw.fsf@gmail.com> <831rnvly58.fsf@gnu.org> <83r1vuiu90.fsf@gnu.org> <87v9l67jrd.fsf@gmail.com> <83imh6ira8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000676fa805a521ac55" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="109325"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 08 13:56:04 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jX1bo-000SJz-0j for ged-emacs-devel@m.gmane-mx.org; Fri, 08 May 2020 13:56:04 +0200 Original-Received: from localhost ([::1]:49556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX1bn-0003KT-1V for ged-emacs-devel@m.gmane-mx.org; Fri, 08 May 2020 07:56:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX1bH-0002ow-PO for emacs-devel@gnu.org; Fri, 08 May 2020 07:55:31 -0400 Original-Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]:46881) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jX1bG-0001ja-TM; Fri, 08 May 2020 07:55:31 -0400 Original-Received: by mail-lf1-x129.google.com with SMTP id g10so1168730lfj.13; Fri, 08 May 2020 04:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AgNQHp4ET6OLOcNOfZdm04RIlQmFSwJklpw4Hr39/TU=; b=vHh7G1HABf+KSj2XD/3qY/AdDkYi2e7CkhPfBglzgTsp+KqoHxmnzpVinBiEMCaCms TuLc6X+Br2Ap+6Sl8uhpSBIMGV6MOOC7FIxeappkYJtvQVRkvn1z1pVek5/ApJ7A+W2S QPVsn6NRLDG9ksSVAVdiZ7HyF0xa+lWVqu3jEMOevK9RmQXuOOaj7IrwFFm76rWR1lSA sa2IpEnECNLqAhp7x0jpXqdDZzsChFAR8fGPaL7y3PEIFCIXzFVR+WHvLEgTDbXpY+Vb putu0lrytaLecw/JOob1KyGV0WKMDmleb2FZnJENgaIXlEvcZLDSTFI/ZD7gW8B04lyh QS0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AgNQHp4ET6OLOcNOfZdm04RIlQmFSwJklpw4Hr39/TU=; b=CSWN5tKLQ1RU2C1zNIFNO7vmqoY5Rt7xcbiSUCuVX2W5Lpo9j5JUHl6+9W1HjqXgfi I3pwrQfG6dMbgxv2mp5VjrIWlFWE4hBry674GivYb+EGGaoaghXsUFc+irv1dV1OFnzu ttB8irGRTq7R73HBRIjZ69qd7d995BCrNOQI8T0mytqkoCoGFvT7w4D/RV2UyX1UHzJy wZBQ5x55BEHbd3ZwPgcGswL7PDmvIGhaUBV+C+RM8tdLm3cjl99a6BNLdVIEREFQDXQQ 8EOqRe0XgVxLP1WEr7NcR/oh/kqn2jTnAZSXiPP2rrVaXwjZEzypIMysCn4MJIo1BMhn rYaA== X-Gm-Message-State: AOAM531aWGMVCbop1c7WaLXwDYk6XARv2HwnV9LaXW7uc5wtJrMKIrR9 CCGD2zCoD6F1xC1hVGyIMewI/H7PQqL+DiIy/8I7sds2 X-Google-Smtp-Source: ABdhPJxSfmOxwtY80uJXnz4GY2B/O5PQlfAHE+1MMPL00WyiQCTVDTCRNuDj4OBTdTGrqLyBi+xV/OQjfdoEG9zVsBQ= X-Received: by 2002:ac2:4c29:: with SMTP id u9mr1667829lfq.209.1588938928515; Fri, 08 May 2020 04:55:28 -0700 (PDT) In-Reply-To: <83imh6ira8.fsf@gnu.org> Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=yyoncho@gmail.com; helo=mail-lf1-x129.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:249269 Archived-At: --000000000000676fa805a521ac55 Content-Type: text/plain; charset="UTF-8" Hi Eli, Threads seem to the correct solution for the problem I am trying to solve. Thank you for your help. Thanks, Ivan On Fri, May 8, 2020 at 2:45 PM Eli Zaretskii wrote: > > From: Ivan Yonchovski > > Cc: emacs-devel@gnu.org > > Date: Fri, 08 May 2020 14:23:34 +0300 > > > > (defun process-events () > > (when (input-pending-p) > > (run-with-timer 0.01 nil (lambda () (throw 'exit nil))) > > (recursive-edit))) > > > > (dotimes (counter 1000) > > (sleep-for 0.01) ;; simulate execution of N tasks > > (message "%s" counter) > > (process-events)) > > > > This code is able to handle C-n but obviously it will break if someone > > starts another recursive-edit or for complex keybindings, e. g. `C-x b`. > > I think you will indeed find that this is very fragile. > > > Are you aware of something doing something similar? Do you think it > > makes sense if you want to process something slow on the background > > without blocking emacs? > > I think this is why we added threads to Emacs. Why not try doing this > in a thread? > > > > AFAIU, such facilities need to have a separate event loop that > > > generally runs in a separate thread. > > > > In the C# case it all happens on the UI thread. DoEvents means handle > > mouse clicks, repaint controls, etc(the stuff from the event loop) and > > then continue with current execution. > > When display is as intimately connected to the global state as it is > in Emacs, I don't think such separation can fly. > --000000000000676fa805a521ac55 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Eli,

Threads seem to the correct sol= ution for the problem I am trying to solve. Thank you for your help.
<= div>
Thanks,
Ivan

On Fri, May 8, 2020 at 2:45 = PM Eli Zaretskii <eliz@gnu.org> w= rote:
> From:= Ivan Yonchovski <yyoncho@gmail.com>
> Cc: emacs-dev= el@gnu.org
> Date: Fri, 08 May 2020 14:23:34 +0300
>
> (defun process-events ()
>=C2=A0 =C2=A0(when (input-pending-p)
>=C2=A0 =C2=A0 =C2=A0(run-with-timer 0.01 nil (lambda () (throw 'exi= t nil)))
>=C2=A0 =C2=A0 =C2=A0(recursive-edit)))
>
> (dotimes (counter 1000)
>=C2=A0 =C2=A0(sleep-for 0.01) ;; simulate execution of N tasks
>=C2=A0 =C2=A0(message "%s" counter)
>=C2=A0 =C2=A0(process-events))
>
> This code is able to handle C-n but obviously it will break if someone=
> starts another recursive-edit or for complex keybindings, e. g. `C-x b= `.

I think you will indeed find that this is very fragile.

> Are you aware of something doing something similar? Do you think it > makes sense if you want to process something slow on the background > without blocking emacs?

I think this is why we added threads to Emacs.=C2=A0 Why not try doing this=
in a thread?

> > AFAIU, such facilities need to have a separate event loop that > > generally runs in a separate thread.
>
> In the C# case it all happens on the UI thread. DoEvents means handle<= br> > mouse clicks, repaint controls, etc(the stuff from the event loop) and=
> then continue with current execution.

When display is as intimately connected to the global state as it is
in Emacs, I don't think such separation can fly.
--000000000000676fa805a521ac55--