Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

No one wants war. -- Kirk, "Errand of Mercy", stardate 3201.7


devel / comp.lang.tcl / Re: Blocking ::http::geturl?

SubjectAuthor
* Blocking ::http::geturl?Silas Silva
`* Blocking ::http::geturl?Rich
 `- Blocking ::http::geturl?Silas Silva

1
Blocking ::http::geturl?

<554af137-46bb-4546-96f1-fe2ed9c497fdn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12705&group=comp.lang.tcl#12705

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:474e:0:b0:428:31c9:6aaa with SMTP id k14-20020ac8474e000000b0042831c96aaamr350483qtp.9.1704315287932;
Wed, 03 Jan 2024 12:54:47 -0800 (PST)
X-Received: by 2002:ac8:5f8b:0:b0:428:3711:6729 with SMTP id
j11-20020ac85f8b000000b0042837116729mr186820qta.3.1704315287663; Wed, 03 Jan
2024 12:54:47 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 3 Jan 2024 12:54:47 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=189.29.145.215; posting-account=NxMiCgoAAABxQSUk_zCywqpH-0JPy1cJ
NNTP-Posting-Host: 189.29.145.215
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <554af137-46bb-4546-96f1-fe2ed9c497fdn@googlegroups.com>
Subject: Blocking ::http::geturl?
From: sila...@gmail.com (Silas Silva)
Injection-Date: Wed, 03 Jan 2024 20:54:47 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Silas Silva - Wed, 3 Jan 2024 20:54 UTC

Hello there!

I've written a very simple Tk application that is very serial. Recently I added support for http requests like this:

set token [::http::geturl example.com]
set data [::http::data $token]
(configure .toplevel.mywidget with $data)

I soon discovered that ::http::geturl doesn't block the main loop, which is great, but it happens that for my very serial application, it can be problematic sometimes. For instance: sometimes I destroy the toplevel in which mywidget lives before it got a chance to receive $data, so when geturl resumes its execution, my code throws an error because it tries to configure mywidget.

The easiest solution I thought was to make ::http::geturl blockable, but I couldn't. I tried ::http::wait (with -command), vwait and tkwait, with no success. Yes, guys, making this GUI block would be perfect for me, since I'm the sole user of this small application :-) Can I?

Alternatively, is there a more elegant solution that is not to add a bunch of if's to check if widgets still exist?

Thank you very much and I hope you have a great 2024!

Re: Blocking ::http::geturl?

<un4ri8$3ccdi$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12710&group=comp.lang.tcl#12710

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Blocking ::http::geturl?
Date: Wed, 3 Jan 2024 23:45:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <un4ri8$3ccdi$2@dont-email.me>
References: <554af137-46bb-4546-96f1-fe2ed9c497fdn@googlegroups.com>
Injection-Date: Wed, 3 Jan 2024 23:45:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="13960a1403a24495467ca237d11c097d";
logging-data="3551666"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19N/0jEDwEvs6vcpdXdq4JP"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:U068NmzdHvve6C+0310zSPa9158=
 by: Rich - Wed, 3 Jan 2024 23:45 UTC

Silas Silva <silasdb@gmail.com> wrote:
> Hello there!
>
> I've written a very simple Tk application that is very serial.
> Recently I added support for http requests like this:
>
> set token [::http::geturl example.com]
> set data [::http::data $token]
> (configure .toplevel.mywidget with $data)
>
> I soon discovered that ::http::geturl doesn't block the main loop,
> which is great, but it happens that for my very serial application,
> it can be problematic sometimes. For instance: sometimes I destroy
> the toplevel in which mywidget lives before it got a chance to
> receive $data, so when geturl resumes its execution, my code throws
> an error because it tries to configure mywidget.
> [...]
> Alternatively, is there a more elegant solution that is not to add a
> bunch of if's to check if widgets still exist?

If it is just a missing toplevel, you could wrap the 'configure' in a
try:

try {
configure .toplevel.mywidget with $data
} on error {a b} {
# do whatever you should do here when the configure fails
}

Or you can check for the toplevel before trying to configure it:

if {[winfo exists .toplevel]} {
configure .toplevel.mywidget with $data
} else {
# do what you need to do when the toplevel has been destroyed
}

Note that the "do whatever" should include freeing the return token
from geturl, otherwise you will have a memory leak.

Re: Blocking ::http::geturl?

<f91f97bf-8d20-4d0e-83e8-6ff459e3ac7cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12713&group=comp.lang.tcl#12713

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:59c7:0:b0:428:3a4e:481d with SMTP id f7-20020ac859c7000000b004283a4e481dmr149154qtf.0.1704392574032;
Thu, 04 Jan 2024 10:22:54 -0800 (PST)
X-Received: by 2002:a05:622a:6:b0:428:3673:4a58 with SMTP id
x6-20020a05622a000600b0042836734a58mr204116qtw.12.1704392573776; Thu, 04 Jan
2024 10:22:53 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 4 Jan 2024 10:22:53 -0800 (PST)
In-Reply-To: <un4ri8$3ccdi$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=177.104.48.4; posting-account=NxMiCgoAAABxQSUk_zCywqpH-0JPy1cJ
NNTP-Posting-Host: 177.104.48.4
References: <554af137-46bb-4546-96f1-fe2ed9c497fdn@googlegroups.com> <un4ri8$3ccdi$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f91f97bf-8d20-4d0e-83e8-6ff459e3ac7cn@googlegroups.com>
Subject: Re: Blocking ::http::geturl?
From: sila...@gmail.com (Silas Silva)
Injection-Date: Thu, 04 Jan 2024 18:22:54 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Silas Silva - Thu, 4 Jan 2024 18:22 UTC

On Wednesday, January 3, 2024 at 8:45:17 PM UTC-3, Rich wrote:
> If it is just a missing toplevel, you could wrap the 'configure' in a
> try:

Thanks for the answer. That was what I was doing, but I ended up just "freezing" the UI using [tk busy] (suggestion from schelte in the Tcler's Chatroom. Thanks!). Anyway, I'll surround code with [try] or a check as you suggested, specially in places where [tk busy] does not solve my particular problem.

Thank you very much!

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor