1,813 questions
1
vote
4
answers
89
views
When does python 3 execute the beginning of a generator function?
Python 3 seems not to execute the beginning of a generator function, from its first line up to the first yield at the time when the function is first called. Python seems to defer the initial ...
0
votes
0
answers
118
views
boost::asio::io_context stops running new tasks
I'm encountering an issue with the Boost.Asio library. My program uses a single io_context instance and multiple worker threads that call io_context::run(). Tasks are posted using spawn or post on the ...
1
vote
0
answers
98
views
Utility of yield keyword in f sharp
So far I know, we use it mostly for list/array comprehension. Here is two codes:
[ for x in range do (yield expression)]
else we can also drop the yield and still it works
[ for x in range do ...
-1
votes
3
answers
190
views
Is it possible to use 'foreach' on the same IEnumerable twice or more inside a method with 'yield'?
Very simple case: I have a list of items (1, 2, 3, 4, 5, 6, 7, 8, 9, 10). I need to filter it and drop a few first elements and a few last elements and to get a few items from the middle (for example ...
0
votes
0
answers
68
views
I am yielding to an ERB file, but it is rendering in plain text and not HTML. Why?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0&...
2
votes
2
answers
276
views
How to access the last value in an async generator after a for await...of?
When using for await...of to iterate over an async generator, the final value (return value) seems to be consumed and inaccessible afterward. Here's a minimal example:
async function* exampleGenerator(...
1
vote
1
answer
68
views
The yield command will not work as it should in Ruby
In the book "The Well-Grounded Rubyist" edition 3 on page 185 is the code. And the code for my_each is on page 183. It also involve code on page 184:
Class Array
# Put the definition of ...
2
votes
2
answers
76
views
Python - Generator not working with next method
I created a generator to perform pagination on an api:
def page_helper(req, timeout=5, page=1, **kwargs):
print(f"Page {page}", end="\r")
try:
response = req(params=...
0
votes
1
answer
92
views
How to force a stateful widget to redraw when setting state from within a "yielding stream" listener?
Nothing crazy what I am trying to achieve but I pull my hair on it for days.
I basically want to achieve the following: a long running process does internet accesses and processing of data with many ...
0
votes
1
answer
60
views
Python skips recursion if yield is present
I have the following XML file:
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:okp=&...
1
vote
3
answers
118
views
how to catch throw and other exceptions in coroutine with 1 yield?
I have var DICTIONARY, which is a dictionary where the keys are English letters and the values are words that start with the corresponding letter. The initial filling of DICTIONARY looks like this:
...
-1
votes
1
answer
57
views
how to generate correct output using 2 yield statements in coroutine?
i have var DICTIONARY, which is a dictionary where the keys are English letters and the values are words that start with the corresponding letter. The initial filling of DICTIONARY looks like this:
...
0
votes
1
answer
59
views
How to yield only newly generated text
I have a Flask application that uses a RAG pipeline in the background, and I stream responses from vLLM. I'm currently using a function to parse and yield the streamed JSON responses. However, I'm ...
0
votes
1
answer
118
views
ensure connection inside generator function is closed by caller [closed]
Today, while programming, I found myself managing a resource (ssh connection) inside a generator function, something similar to the following:
#I decided to use a generator to avoid looping through ...
1
vote
1
answer
309
views
Simplest way in C# to defer task execution without synchronization context [closed]
Inside an async method in C#, I need to defer the execution (return the execution to the caller), and also to clear the synchronization context before proceeding with the execution.
The statement ...