Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1264

Python • Re: Concurrent Processing Problem

$
0
0
Same error like the last try:

Code:

exe.submit(Step(1,300,0.001,'b'))
This submits the Return Value of the function Step(). First the function is called, then the result is given as Argument to exe.submit. In Python function are first class functions. You can use a function as an argument for another function/method.


Example:

Code:

class FakePool:    def __enter__(self):        return self    def __exit__(self, *args):        pass    def submit(self, function, /, *args, **kwargs):        print(f"Calling {function} with {args=} and {kwargs=}")        function(*args, **kwargs)def step(step_id, position, direction):    print("Function step called:", step_id, position, direction)print("# right")with FakePool() as pool:    pool.submit(step, 1, 3000, "b")print()print("# wrong")with FakePool() as pool:    try:        pool.submit(step(1, 3000, "b"))    except TypeError:        print("You can't call None!")
Output:

Code:

# rightCalling <function step at 0x77e620404fe0> with args=(1, 3000, 'b') and kwargs={}Function step called: 1 3000 b# wrongFunction step called: 1 3000 bCalling None with args=() and kwargs={}You can't call None!
Before you start the next post, learn Python. This is required basic knowledge.

Statistics: Posted by DeaD_EyE — Sun Feb 18, 2024 7:58 pm



Viewing all articles
Browse latest Browse all 1264

Trending Articles