#Python randomly changing values [bug?]
1 messages ยท Page 1 of 1 (latest)
you may be dealing with race conditions
Elaborate. Please review code before giving an answer.
I don't wanna deal with assumptions.
is your bot used often?
My bot is only used in one Discord Server and used by 2-3 people at a time.
The games tend to work fine but then randomly the bug happens as mentioned above and shown in the screenshot.s
I've read all through my code and I don't see how it's possible for Python to be messing this up as mathmatically it isn't possible.
I have no idea where it's getting the numbers from or anything.
tbf, does look like race conditions. Doesn't really depend how many users they have. If they are handled at the same time, same variable or so, it could occur
always need to make it threadsafe in this case
(eg. using locks)
I'm not understanding?
Can you look at my code and tell me if it's anything in there? I don't think it is cause the code doesn't seem like it'd be able to do that.
Also I don't know what you mean by race conditions.
Nor how to prevent it.
did you verify the contents of the json file are right?
Wdum?
The Json Database is fine no issues with it.
i literally sent a link to the definition
also your push function has a little error
it changes the balance of the player
Uh wdum
But that doesn't really makesense to me.
Push isn't an issue push works fine.
async def push(self, bust = False):
cas = self.cas
money = "{:,}".format(cas["money"]) #on push they don't win nor lose anything
embed = discord.Embed(title="You Pushed [Blackjack]",description=f"**Game ID**: `{self.id_value}`\n*Use `/lookup` to view this game.*",color=p84clr)
embed.add_field(name=f"Player [{self.player.value()}]",value=f"{self.player}")
embed.add_field(name=f"Dealer [{self.dealer.value()}]",value=f"{self.dealer}")
embed.add_field(name="Profit",value=f"`$0`", inline=False)
embed.add_field(name="Balance",value=f"`${money}`")
if self.message:
await self.message.edit(None, embed = embed, view = None)
self.changeBalance(self.owner, round(self.bet)) # i believe this isnt supposed to be here```
Ye
it doesn't change their balance tho
Since byAmount is 0
It just sets it to their money.
Not the issue nor the focus.
ah whatever
race condition is basically when two threads for instance try to write to the same variable for instance
only one of the two threads gets their result saved permanently afterwards
hm
How would that happen if I have a 5 second cooldown on all commands?
Plus an in-game prevention system so no duel games happen.
very unlikely but you should still check
this ones a toughie ยฏ_(ใ)_/ยฏ
Yup.
So what do I do to fix it?.
I've tested it myself and there's no explanation other to say it randomly just happens.
It happens even if you don't spam it. I took a 30 min break, came back.. happened.
So I don't understand.
Anyone know how to fix it ๐ฆ
I told you, locks
Pardon the Google URL, am on the phone
Just search for python thread safety and python locks
It makes no sense
How do you even know thats the issue
just to confirm the issue is related to the json and database?
Educated guess after years of professional python development ... You got a condition going on where variables are being changed in between start and end
It's the only explanation
So in your example does the json have $20,000 or $6,789?
Even if it is in the JSON dB, you got to make it safe for concurrency
$6789
But it should have $20,000? So the json is wrong
In that particular demo i didnt have an exact answer. The database is always changing so hard to get an exact answer.
Would it be what Fishy said being the lock issue?
Bruh locking isn't rlly explained anywhere and that isn't even the issue I was having.
F
and joined and left again ๐
look in other one
miner mends is kinda dumb tbf
he dmed me, I asked him why, he then deleted his message and dmed me "what"
๐