need help with my program

posted in Off Topic
View:
Threaded
Linear
Linear
#1
Foxym
0
Frags
+
–

regarding the program used for this: https://www.vlr.gg/651575/vct-teams-lifetime-data-part-2

im trying to add multiprocessing to it
but i cant figure it out for the life of me
https://i.ibb.co/nshjSfR4/image-1778892995944.png

errors im getting

RuntimeError
ConnectionResetError: [Errno 104] Connection reset by peer

im considering sticking with the "just sleep through it" method

#2
NotaSenFan27
2
Frags
+
–

claude ai

#3
Foxym
1
Frags
+
–
NotaSenFan27 [#2]

claude ai

fuck off

#4
NotaSenFan27
0
Frags
+
–
Foxym [#3]

fuck off

not all ai is bad ai

#5
delighted
0
Frags
+
–

use threading first, add retries with backoff

and lower the concurrency

#6
Foxym
0
Frags
+
–
delighted [#5]

use threading first, add retries with backoff

and lower the concurrency

did try using them, did not figure out how to run multiple threads at once
(prolly cause i didnt use the "args" thingy and just put it directly into it
like this:

threading.Threads(target=Calculate_Event_Stats(VCT_TEAMS[x], aom=0)

)

edit:
what is concurrency
it is currently 3am for me so im a bit slow rn

#7
delighted
0
Frags
+
–
Foxym [#6]

did try using them, did not figure out how to run multiple threads at once
(prolly cause i didnt use the "args" thingy and just put it directly into it
like this:

threading.Threads(target=Calculate_Event_Stats(VCT_TEAMS[x], aom=0)

)

edit:
what is concurrency
it is currently 3am for me so im a bit slow rn

isn't concurrency multiple tasks making progress during overlapping times

#8
31Raven
0
Frags
+
–

did u try turning it off and on again

#9
verybluepond
0
Frags
+
–

you should probably test if calculate_vct_stats() actually hits vlr before trying to parallelize tbh

also your inner loop looks like it's stepping through just test[0] and test[1] for the length of your test array.
Write a straightforward module with a single data point and process first and verify it runs before trying to do tricks.

#10
verybluepond
-1
Frags
+
–
delighted [#5]

use threading first, add retries with backoff

and lower the concurrency

concurrency jumpscare

I'm probably talking to a bot but the `multiprocessing` module is used to bypass the GIL for "truly parallel code" so if speed is what he's looking for this is better, although the % gains would probably have to be measured, I don't think it's all that faster for this block of code

#11
delighted
0
Frags
+
–
verybluepond [#10]

concurrency jumpscare

I'm probably talking to a bot but the `multiprocessing` module is used to bypass the GIL for "truly parallel code" so if speed is what he's looking for this is better, although the % gains would probably have to be measured, I don't think it's all that faster for this block of code

the GIL only matters for CPU heavy work iinw

#12
verybluepond
-1
Frags
+
–
delighted [#11]

the GIL only matters for CPU heavy work iinw

this is pretty literally trying to get more juice out of the CPU, prompt your shit correctly brother

#13
BabyWizard
0
Frags
+
–

This is too confusing im scared

#14
Foxym
0
Frags
+
–
verybluepond [#9]

you should probably test if calculate_vct_stats() actually hits vlr before trying to parallelize tbh

also your inner loop looks like it's stepping through just test[0] and test[1] for the length of your test array.
Write a straightforward module with a single data point and process first and verify it runs before trying to do tricks.

if you mean "gets info from vlr"
yeah it does

if i dont do multiprocessing but use the old way i compiled the data i get no issues
but its slow because it goes through each team 1 by 1
https://i.ibb.co/mCM7zfQ7/image-1778929657881.png

but hey it works

as for a single Multiprocessing process, im still getting the same errors

RuntimeError
ConnectionResetError: [Errno 104] Connection reset by peer
#15
Foxym
0
Frags
+
–
BabyWizard [#13]

This is too confusing im scared

understandable

#16
verybluepond
0
Frags
+
–
Foxym [#14]

if you mean "gets info from vlr"
yeah it does

if i dont do multiprocessing but use the old way i compiled the data i get no issues
but its slow because it goes through each team 1 by 1
https://i.ibb.co/mCM7zfQ7/image-1778929657881.png

but hey it works

as for a single Multiprocessing process, im still getting the same errors

RuntimeError
ConnectionResetError: [Errno 104] Connection reset by peer

write like so:

p = multiprocessing.Process(target=your_callable, args=(VCT_TEAMS[0],))

p.start()
p.join() 

what does it show then? the formatting might be bad cause I typed out on mobile, but legible enough

#17
Foxym
0
Frags
+
–
verybluepond [#16]

write like so:

p = multiprocessing.Process(target=your_callable, args=(VCT_TEAMS[0],))

p.start()
p.join() 

what does it show then? the formatting might be bad cause I typed out on mobile, but legible enough

same errors, maybe a screenshot would explain more

https://i.ibb.co/9HMFFdgL/image-1778931887588.png

https://i.ibb.co/3y0mZ1V1/image-1778931957993.png

#18
verybluepond
0
Frags
+
–
Foxym [#17]

same errors, maybe a screenshot would explain more

https://i.ibb.co/9HMFFdgL/image-1778931887588.png

https://i.ibb.co/3y0mZ1V1/image-1778931957993.png

oh run it with the proper entry point then
` if name = 'main' :

you have to specify the entry point to the script explicitly to avoid spawning new processes before the current process is fully init

add: If this actually runs, I would point you to the multiprocessing.Pool() functionality for pythonic parallelization

#19
Foxym
0
Frags
+
–
verybluepond [#18]

oh run it with the proper entry point then
` if name = 'main' :

you have to specify the entry point to the script explicitly to avoid spawning new processes before the current process is fully init

add: If this actually runs, I would point you to the multiprocessing.Pool() functionality for pythonic parallelization

im now getting this error
https://i.ibb.co/m5VghR1R/image-1778933534193.png

#20
CrackedDuelist
-1
Frags
+
–
verybluepond [#12]

this is pretty literally trying to get more juice out of the CPU, prompt your shit correctly brother

you have encountered the #1 larper on this site

#21
verybluepond
0
Frags
+
–
Foxym [#19]

im now getting this error
https://i.ibb.co/m5VghR1R/image-1778933534193.png

I believe you see some output at the top (running the whole program took x secs) from your script so it looks like it's running? progress

after your p.start() add a p.join() or your time.sleep(20) to pause execution until your child process is done, allow for resource cleanup basically

#22
Foxym
0
Frags
+
–
verybluepond [#21]

I believe you see some output at the top (running the whole program took x secs) from your script so it looks like it's running? progress

after your p.start() add a p.join() or your time.sleep(20) to pause execution until your child process is done, allow for resource cleanup basically

my issue is the index error
something about openpyxl
https://i.ibb.co/9kmWNb1p/image-1778934188707.png
i think this is the issue
no idea how i will get this panda output
https://i.ibb.co/67fqN3MW/image-1778934273311.png
into like a functioning thing for the excel spreadsheet writing

#23
verybluepond
0
Frags
+
–
Foxym [#22]

my issue is the index error
something about openpyxl
https://i.ibb.co/9kmWNb1p/image-1778934188707.png
i think this is the issue
no idea how i will get this panda output
https://i.ibb.co/67fqN3MW/image-1778934273311.png
into like a functioning thing for the excel spreadsheet writing

what format does the scraper return the data in? JSON? verify format first, the read into pandas, then call to_csv() afterwards. You don't really need to serialise into .xlsx, that's not very popular, excel reads csvs either way

#24
Foxym
0
Frags
+
–
verybluepond [#23]

what format does the scraper return the data in? JSON? verify format first, the read into pandas, then call to_csv() afterwards. You don't really need to serialise into .xlsx, that's not very popular, excel reads csvs either way

the scraped format should be Html
https://i.ibb.co/6Rp4HVW0/image-1778935199809.png

as for the error, its reporting that no sheet available
my assumption is that while the subprocess compiles data, the main program just passes through and runs the next lines as normal

#25
verybluepond
0
Frags
+
–
Foxym [#24]

the scraped format should be Html
https://i.ibb.co/6Rp4HVW0/image-1778935199809.png

as for the error, its reporting that no sheet available
my assumption is that while the subprocess compiles data, the main program just passes through and runs the next lines as normal

if it's written correctly, it shouldn't create the sheet until our sub process completes.

my eyes are lowkey hurting, so lemme see if I can spell out the correct flow.

we run scraper in parallel, then retrieve a result object, then we extract the text content from the result object and serialise using pandas or some other library and save. That's it.

you don't need to write to the sheet before u've gotten the entire result object, that seems to lead to some kind of race condition during writes as u're seeing. U have a thousand lines (scary, there shouldn't be so much code?) so there are a lot of moving parts I'm not seeing, but if u follow this sequence step by step u should be fine.

For the multiprocessing, isolate that part of your code and test it runs. Then use Pool() properly.

#26
Foxym
0
Frags
+
–
verybluepond [#25]

if it's written correctly, it shouldn't create the sheet until our sub process completes.

my eyes are lowkey hurting, so lemme see if I can spell out the correct flow.

we run scraper in parallel, then retrieve a result object, then we extract the text content from the result object and serialise using pandas or some other library and save. That's it.

you don't need to write to the sheet before u've gotten the entire result object, that seems to lead to some kind of race condition during writes as u're seeing. U have a thousand lines (scary, there shouldn't be so much code?) so there are a lot of moving parts I'm not seeing, but if u follow this sequence step by step u should be fine.

For the multiprocessing, isolate that part of your code and test it runs. Then use Pool() properly.

i set up a pastebin for you to check
might help
just as a slight warning, this is terrible to read
most of the stuff that prolly give the error are closer to the end
https://pastebin.com/YareLXiX

#27
NekoSugarGirls17
0
Frags
+
–

you need more RAM

#28
Foxym
0
Frags
+
–
NekoSugarGirls17 [#27]

you need more RAM

then give me the money for that
im broke

#29
verybluepond
0
Frags
+
–
Foxym [#26]

i set up a pastebin for you to check
might help
just as a slight warning, this is terrible to read
most of the stuff that prolly give the error are closer to the end
https://pastebin.com/YareLXiX

alright I'll take a look when I'm not afk. If I get it to work I'll paste back here.

#30
Foxym
0
Frags
+
–
verybluepond [#29]

alright I'll take a look when I'm not afk. If I get it to work I'll paste back here.

thank you
if you want you can sign off your work

#31
NekoSugarGirls17
0
Frags
+
–
Foxym [#28]

then give me the money for that
im broke

you can download ram for free bro

#32
Foxym
0
Frags
+
–
NekoSugarGirls17 [#31]

you can download ram for free bro

swap space
and no, you cant download that
you need to set it up through the terminal (in linux atleast)

#33
verybluepond
0
Frags
+
–
Foxym [#30]

thank you
if you want you can sign off your work

gimme your previous stats without parallel exec

Seems it's just a couple of lines (I'm not refactoring anything, just adding)

#34
verybluepond
0
Frags
+
–
Foxym [#30]

thank you
if you want you can sign off your work

alr I gotta bounce king. Code below (didn't touch anything except the multiprocessing part). when ur done actually fix ur variable names, hard to navigate.

included some helpful comments
https://pastebin.com/axTfnTum
script takes an avg of ~ 450 seconds to fully compile now (5 run experiment,, idk if that's better or not. 👍

add: https://ibb.co/LbKMfWg

#35
Foxym
0
Frags
+
–
verybluepond [#33]

gimme your previous stats without parallel exec

Seems it's just a couple of lines (I'm not refactoring anything, just adding)

a full compilation of all VCT teams took 6 hours last time (all 48 teams)

#36
verybluepond
0
Frags
+
–
Foxym [#35]

a full compilation of all VCT teams took 6 hours last time (all 48 teams)

see below, run it now

#37
Foxym
0
Frags
+
–
verybluepond [#34]

alr I gotta bounce king. Code below (didn't touch anything except the multiprocessing part). when ur done actually fix ur variable names, hard to navigate.

included some helpful comments
https://pastebin.com/axTfnTum
script takes an avg of ~ 450 seconds to fully compile now (5 run experiment,, idk if that's better or not. 👍

add: https://ibb.co/LbKMfWg

thanks mate
though, how can i add more arguments

#38
verybluepond
0
Frags
+
–
Foxym [#37]

thanks mate
though, how can i add more arguments

just modify state in your function to account for extra arguments. map() takes only f and iterable, either work with that or swap out for map_async with a callback chain. Real modular codebases use multiprocessing in tandem with context managers and stuff for proper management, but this is just a script. No point, I don't think. You can refactor in future if u want though.

Overall rtfm, it's a good read -> https://docs.python.org/3/library/multiprocessing.html

#39
zappp
0
Frags
+
–
delighted [#5]

use threading first, add retries with backoff

and lower the concurrency

who is down voting my guy

#40
tubelight
0
Frags
+
–

You will need to win a lottery for this (ram)

#41
OmenEnthusiast
-1
Frags
+
–
Foxym [#32]

swap space
and no, you cant download that
you need to set it up through the terminal (in linux atleast)

nah just try this: https://downloadmoreram.com/ it works, trust

#42
Foxym
0
Frags
+
–
verybluepond [#38]

just modify state in your function to account for extra arguments. map() takes only f and iterable, either work with that or swap out for map_async with a callback chain. Real modular codebases use multiprocessing in tandem with context managers and stuff for proper management, but this is just a script. No point, I don't think. You can refactor in future if u want though.

Overall rtfm, it's a good read -> https://docs.python.org/3/library/multiprocessing.html

do you know how i can restore data sorting and the excel writing functionallity so i dont lose the data points in the terminal and dont spend hours organizing the data myself?

#43
verybluepond
0
Frags
+
–
Foxym [#42]

do you know how i can restore data sorting and the excel writing functionallity so i dont lose the data points in the terminal and dont spend hours organizing the data myself?

did I delete that? I don't think so.

read your created txt files into pandas and manipulate as u wish, or do it at some other place in your Team_File creation process.

#44
Foxym
1
Frags
+
–
verybluepond [#43]

did I delete that? I don't think so.

read your created txt files into pandas and manipulate as u wish, or do it at some other place in your Team_File creation process.

no, you commented it out
i think i should make a second python program for that then
when its done with compiling

#45
ari
0
Frags
+
–
verybluepond [#12]

this is pretty literally trying to get more juice out of the CPU, prompt your shit correctly brother

I'm crying bro he has no idea what he's talking about

  • Preview
  • Edit
› check that that your post follows the forum rules and guidelines or get formatting help
Sign up or log in to post a comment