source-python

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

source-python

Postby daren adler » Tue May 21, 2019 7:43 pm

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
Last edited by Ayuto on Tue May 21, 2019 8:00 pm, edited 1 time in total.
Reason: Added code tags
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: source-python

Postby satoon101 » Tue May 21, 2019 7:45 pm

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.
Image
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: source-python

Postby daren adler » Tue May 21, 2019 7:52 pm

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?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: source-python

Postby satoon101 » Tue May 21, 2019 7:59 pm

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))
Image
DeaD_EyE
Member
Posts: 34
Joined: Wed Jan 08, 2014 10:32 am

Re: source-python

Postby DeaD_EyE » Tue May 28, 2019 5:18 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 25 guests