@trtt I thought I gave you example, but anyway, it's here
[https://github.com/mashingan/nim-etc/blob/master/cond_loop.nim](https://github.com/mashingan/nim-etc/blob/master/cond_loop.nim)
I don't have the code yet because I'm about to write it(actually, I've a very
different code but the problem is that I need the timeout mechanism, otherwise
the program can't cooperate properly). But I'll quote my problem again:
"I need this to be able to communicate with another pr
I don't know details of your application, but...
What you could do is store the `FlowVar` (the object that spawn returns) for
the thread that is waiting for stdin, wait for the FlowVar to finish for
timeout seconds. If it finishes before timeout then use the returned value and
re-spawn
Ok, but I need a timeout too, non-blocking stdin is not enough.
`stdin` will block a whole thread (this is not nim specific), so you need to
spawn a reader thread to read from stdin, async will not work.
Note that how to read from `stdin` in a non-blocking way seems to be a popular
question on Google search as there are Gevents, Python, D, Rust, Vala and
How would you instruct it to quit if it's blocked by stdin?
Directly, you can't. But you can instruct it through channel to
break/return/quit your other thread.
Just message it to quit and put the logic when receiving the message that your
thread is to quit.
Sorry, I don't understand - can I suspend or kill a parallel concurrency unit
with that?
try with combination of channel, lock and condition ?
like this
[example](https://forum.nim-lang.org/\(https:/github.com/mashingan/nim-etc/blob/master/cond_loop.nim)
I want to kill the thread after a certain amount of time. I need this to be
able to communicate with another program in a single thread without blocking
forever and without race issues.
What do you mean by "intercept"? And why do you need this?
Is it possible to intercept the thread? I couldn't find anything in the
threadpool module...
Here is an example of how to mix stdin reading (with spawn) with async IO:
[https://github.com/dom96/nim-in-action-code/blob/master/Chapter3/ChatApp/src/client.nim#L38-L50](https://github.com/dom96/nim-in-action-code/blob/master/Chapter3/ChatApp/src/client.nim#L38-L50)
Hi,
I want to timeout the reading from stdin and I couldn't find anything in the
threads and os modules. It'd be also good if I could use stdin/read in a
non-blocking way.
I probably am getting corrupted data at the end of stream, and just not
noticing because ffmpeg does a good enough job at handling bad inputs. :( I'll
take a closer look (and not close `bodyStream` unnecessarily).
That's good information to know about issue 8994. I'll take a look at issue
7126
I can't really think of a better way to do this, the way your doing it looks
good.
I'm not sure why you're closing the `bodyStream` though, I'm surprised that
doesn't cause issues. The HTTP client is only supposed to close it.
Btw, beware of 0.19.0, you might run into a regression if you use
rr: p.TError|p.TErrorCode) =
if cast[p.TErrorCode](err) != p.NoError:
raise newException(Exception, $p.GetErrorText(err))
proc requestAACWithTimeout(client: AsyncHttpClient, url: string, timeout:
int = TIMEOUT_SECONDS) {.async.} =
let resp = await client.get(url)
Okay, cool. Feel free to make a PR for this (it should be configurable and
stored in AsyncFtpClient).
Yes, you can
I modified **asyncftpclient.nim**. See _sendTimeout_ variable that count the
seconds.
The time out is hardcoded to 10s.
proc doUpload(ftp: AsyncFtpClient, file: File,
onProgressChanged: ProgressChangedProc) {.async.} =
assert
Thanks, that clears it up. I only was focused on the middle error message as it
seemed to pertain to the issue at hand . As always reading docs is a real
challenge...
Compiles fine with
Nim Compiler Version 0.17.3 (2017-11-17) [Linux: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf
git hash: 416aa921fa0cfefda5f3ee30329c8378f2e2008a
active boot switches: -d:release
Issues with httpclient timeout
import httpclient
let callav =
"https://github.com/nim-lang/Nim/blob/devel/tests/arithm/tand.nim;
var zcli = newHttpClient()
echo zcli.getContent(callav,timeout = 1) # < fails
#echo zcli.getConten
22 matches
Mail list logo