17, జులై 2025, గురువారం

By Mr Dr...................

 


 def myfunction():  pass  ........without body python generate error , to avoid pass stmt is use



 def f1():

    s = 'Mr.Dr'

    

    def f2():

        print(s)

        

    f2()


f1()

function call with in function ...............MrDr

Anonymous Functions in Python

def cube(x): return x*x*x   # without lambda


cube_l = lambda x : x*x*x  # with lambda


print(cube(7))

print(cube_l(7))

output   343    343  

program

def square_value(num):

     return num**2


print(square_value(2))

print(square_value(-4))

15, జులై 2025, మంగళవారం

NOW IT IS THE TIME TO DICIPHER , Ruby Interpreters and Runtimes..............................

common point of confusion among Ruby developers; namely: Concurrency and parallelism are not the same thing (i.e., concurrent != parallel). In particular, Ruby concurrency is when two tasks can start, run, and complete in overlapping time periods. It doesn’t necessarily mean, though, that they’ll ever both be running at the same instant (e.g., multiple threads on a single-core machine). In contrast, parallelism is when two tasks literally run at the same time (e.g., multiple threads on a multicore processor). The key point here is that concurrent threads and/or processes will not necessarily be running in parallel. This tutorial provides a practical (rather than theoretical) treatment of the various techniques and approaches that are available for concurrency and parallelism in Ruby.

 

let’s try to make the same program faster using Ruby multithreading techniques instead. Multiple threads within a single process have considerably less overhead than a corresponding number of processes since they share address space and memory. With that in mind, let’s revisit our test case, but this time using Ruby’s Thread class:

 threads = []

puts Benchmark.measure{ 100.times do |i| threads << Thread.new do Mailer.deliver do from "eki_#{i}@eqbalq.com" to "jill_#{i}@example.com" subject "Threading and Forking (#{i})" body "Some content" end end end threads.map(&:join) }

This code now yields the following results (again, on a quad-core processor with MRI Ruby 2.0.0p353):

13.710000   0.040000  13.750000 ( 13.740204)
The Global Interpreter Lock is a mechanism used in computer language interpreters to synchronize the execution of threads so that only one thread can execute at a time. An interpreter which uses GIL will always allow exactly one thread and one thread only to execute at a time, even if run on a multi-core processor. Ruby MRI and CPython are two of the most common examples of popular interpreters that have a GIL.