how can I make sem_wait return -1 and errno is EINTR? - wait

I want to test the sem_wait function to make it return -1 and the errno is EINTR and I want to print them.
How can I do this? Can you show me a example?

Related

Recursion countdown: why doesn't this code work? i'm trying to do a simple recursion example, in which i have to print the countdown from 10 to 1

This code should do the countdown, but i receive a unexpected indent error, but i don't hunderstand why.
def countdown(n):
print(n)
if n==1:
return 1
return countdown(n-1)
x=10
print(countdown(x))

Creating plsql function for Factorial program

When I call the function using select statement
[select fact(5) from dual;]
I get output as 1.Can you guys please help me from the below code
create or replace function fact(num in number)
return number
Is
res_fact number:=1;
begin
for i in 1..5 loop
res_fact:=res_fact*i;
dbms_output.put_line(res_fact);
-- dbms_output.put_line('Factorial of '||num||' = '||res_fact);
return res_fact;
end loop;
dbms_output.put_line(res_fact);
end;
res_fact=res_fact*i;
as i call function i used to get the factorial of that input number
res_fact=5*4*3*2*1;
res_fact=120
Make this code "return res_fact;" out of loop you code will run, But above code work for only 5.
Two issues....
Firstly you need to move your return statement outside of your loop. As you now have it it will return on the first pass through the loop.
Secondly you are ignoring your input parameter and always going to get factorial of 5 rather than what is passed in (once you move your return statement.
See code below
create or replace function fact(num in number)
return number
Is
res_fact number:=1;
begin
for i in 1..num loop
res_fact:=res_fact*i;
end loop;
dbms_output.put_line('Factorial of '||num||' = '||res_fact);
return res_fact;
end;

How to use both Run Keyword If and Run Keyword and Return Status?

file.robot
Keyword1
log this is keyword1
${some_value} = Set Variable Hello, world!
[Return] ${some_value}
file2.robot
Some_name
Run keyword If 'True' == 'True Run Keyword and return Status Keyword1
I want to use this way. How do i access the return value in file2.robot
Above, 'Some_name' in file2.robot calls the 'Keyword1', the return value 'some_value' to be printed in 'Some_name' of file2.robot.
How can it be achieved in one-liner as stated above ?
You cannot use a "Run keyword..." command and both get a return value and a pass/fail value. However, if all you need is the return value, Run keyword if will return the result of the keyword that it runs.
For example:
*** Test Cases ***
Example
${the_value}= run keyword if 'True' == 'True' keyword 1
With the above, keyword 1 will only run if the expression evaluates to true. ${the_value} will be set to the result of keyword 1.
If you need both the status and the returned value, you can use Run keyword and return status to run the keyword, but you'll have to modify the keyword to set a suite or global variable that your test can get after the keyword returns.

TypeError: can't convert to int - Micropython

I have arithmetic issues with micropython.
from microbit import *
counter = 0
while True:
display.show('8')
if accelerometer.was_gesture('shake'):
display.clear()
sleep(1000)
counter = counter + 1
display.scroll(counter)
sleep(10)
Error displayed on the LEDs: TypeError: can't convert to int
What am I missing here?
Do you have access to the REPL?
I would test every line on its own in REPL, this way you will now where the error is.
Alternatively delete most of the code until you have something that works, and add one line at a time. Once you have the line with the error it will be much easier to solve.
Start with this:
from microbit import *
counter = 0
while True:
display.show('8')
sleep(10)

xquery empty sequence how to handle

I am trying to return either "Empty" if it is a empty sequence or "NotEmpty" if it is not. Let's say,
for $family in doc("gedcom.xml") /*/FamilyRec
where $family/Child/Link[#Ref = "IN006"]
return if(empty(data($family))) then "Empty" else "NotEmpty"
i am getting result in oxygen: NotEmpty
which is Ok.
but let's say, there is no value for IN005
for $family in doc("gedcom.xml") /*/FamilyRec
where $family/Child/Link[#Ref = "IN005"]
return if(empty(data($family))) then "Empty" else "NotEmpty"
then it should print: Empty
but instead of printing "Empty" I am getting
Engine name: Saxon-EE XQuery 9.3.0.5
Severity: warning
Description: Your query returned an empty sequence.
Can anyone please help me. Thanks in Advance.
If I understand the issue correctly, I think the problem is that your where clause will filter out the value that you're looking for: if "IN005" doesn't exist then it will never get to the return clause.
instead you should not have a where clause and do the check in the return:
for $family in doc("gedcom.xml") /*/FamilyRec
return if($family/Child/Link[#Ref = "IN005"]) then "NotEmpty" else "Empty"
I am trying to return either "Empty" if it is a empty sequence or "NotEmpty" if it is not.
What is "it"?
I'm having trouble working out exactly what your requirements are, but it sounds to me something like:
let $result :=
for ...
where ...
return ...
return (if empty($result) then "Empty" else "Not Empty")

Resources