Page 1 of 1

source-python

Posted: Tue May 21, 2019 7:43 pm
by daren adler
My source-python is working, seems ok on clientside,,but on serverside i get this

Code: Select all

[sp] Caught an Exception:
Traceback (most recent call last)
File " . .\addons\source-python\packages\source-python\listeners\tick.py" , line 80 in tick
    self .pop(0) .execute()
File " . .\addons\source-python\packages\source-python\listeners\tick.py" , line 161 in tick in execute
    return self.callback(*self .kwargs

TypeError: _remove_overlay() argument after * must be an iterable, not int

Re: source-python

Posted: Tue May 21, 2019 7:45 pm
by satoon101
Did you edit the server's ../addons/source-python/packages/source-python/listeners/tick.py file? That line from your Traceback looks incorrect. It should be:
https://github.com/Source-Python-Dev-Te ... ck.py#L161

Not sure how that would happen other than manually editing that file.

Re: source-python

Posted: Tue May 21, 2019 7:52 pm
by daren adler
No i did not know i was to do that, What should i do? and thank you for replying. Can i just download the source-plugin again and grab the folder from there and add it again and see if it still says it?

Re: source-python

Posted: Tue May 21, 2019 7:59 pm
by satoon101
I'm thinking that may have just been a copy/paste issue, because that error wouldn't occur due to that.

The issue is that the script that creates a Delay object is not using args/kwargs correctly. Though, at first glance, I don't see any issues with the code that was linked to in your other thread.

As an example of the right and wrong of your error:

Syntax: Select all

# Right
Delay(2, some_function, (2,))

# Wrong
Delay(2, some_function, 2)

# Also wrong (evaluates to integer not tuple)
Delay(2, some_function, (2))

Re: source-python

Posted: Tue May 28, 2019 5:18 pm
by DeaD_EyE
This is a common pitfall in Python: tuple vs. prioritizing operations
Additionally we have different APIs even in the standard library of Python.

Common pattern:
def caller(function, arguments, keyword_arguments)

In some newer libraries like asyncio a different pattern is used:
def caller(function, *arguments, **keyword_arguments)

The difference is, that in the first pattern, arguments and keyword-arguments are not unpacked.
threading.Thread and multiprocessing.Process follows the first pattern.
functools.partial follows the second pattern.

I see often code like this:

Syntax: Select all

thread = threading.Thread(target=some_function, args=(one_argument,)) # <- the comma is very important


If you forget the comma, it's no longer a tuple. Then it's used for prioritizing operations.

Syntax: Select all

thread = threading.Thread(target=some_function, args=(one_argument))
# exception TypeError occurs


This let you do things like:

Syntax: Select all

text = 'Hello '
name = 'All'
greeting = (text + name).upper()
print(greeting)


To visualize it better, you can use a list literal and then you don't need a comma.

Syntax: Select all

thread = threading.Thread(target=some_function, args=[one_argument])


With the original code:

Syntax: Select all

Delay(2, some_function, [2])



If some_function takes more arguments:
With the original code:

Syntax: Select all

Delay(2, some_function, [2, 1, 3])



Btw: I don't use SourcePython, but I whish this was released in 2004.