#๐ How do i make a ping function?
107 messages ยท Page 1 of 1 (latest)
@warm valve
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
like this;
?ping
Pong! Response: {ms}
is this for a discord bot?
nope
this is for LCP (a project that i'm working on)
like a command panel like a terminal

hello guys???
@lime cosmos
Im gonna need some more context
wait so is this like matrix calculations
what is a matrix calculation?
aw man i want to know how to make this function so badly
wait do u mean LCP array?
what would you be pinging to get the latency then?
i dont know
whats an LCP
since this is a local program if you ping nothing there will be no latency
this probably
they are making their own command panel thingy
yes
;-;
so you want latency but.... it's a command panel?
well yes
yeah what are you trying to get the latency for
;-;
latency of what
whats a latency
i just want the response time
so you essentially want to replicate ping command from system that returns the latency between a server and a client
latency basicallt means response time
see ping gets the time it takes like a server to respond to something
idk maybe just import os
and then when they use the ping command
os.system("ping google.com")```
oh then i want the response time after the ?ping command is inputted
for some cool stuff
thats not what a ping command is supposed to do. its supposed to get the response time of a server
well then
ur definition of "ping" is very vague. define what "ping" is
are you trying to time print()?
github ๐ i gues
ye i guess
๐ ๐
is it just 0?
practically 0 yes
uh
most local operations do not have a latency that you'd need to worry much about (like print)
what are you trying to ping
print()
wtf
theres no point ๐ญ
even though it is 0 it can still be something else
why
!epy import time now = time.time() print("this is a test") after = time.time() time_taken = after - now print(time_taken)
ok
if you have a potato computer
im dumb
its utterly useless
time.time
no, that's not how it works
!e py import time now = time.time() print("this is a test") after = time.time() time_taken = after - now print(time_taken)
@lime cosmos :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | this is a test
002 | 1.9073486328125e-05
if you want to benchmark print function
latency = timeit.timeit("print('Hello')", number=1000) # note: it will print to ur console 1000 times
ty im doing too much stuff with datetime
that is how long it takes to print something
I guess
ohhh alrighty then
eh, you need multiple iterations to reduce error in measurement
!d timeit
Source code: Lib/timeit.py
This module provides a simple way to time small bits of Python code. It has both a Command-Line Interface as well as a callable one. It avoids a number of common traps for measuring execution times. See also Tim Petersโ introduction to the โAlgorithmsโ chapter in the second edition of Python Cookbook, published by OโReilly.
built in
that's seconds
seconds
effectively 0
ok
0.2 ms lol
this is so pointless ๐ญ
yeah milliseconds is multiply by 1000
Why doing this
forreal
print is more likely going to be IO-bound too
(I imagine you've had a fantasy to create something cool looking with menues and you wanted some cool commands and have heard of ping, i am way past that point already btw)
haha
actually it isnt ๐ค
it is kinda useless for print and input unless you are working on cpython internals or something
if youโre asking how to make a proper ping executable like exists on your system, you might like this (very long) blog series https://fasterthanli.me/series/making-our-own-ping
ngl i'd connect using sockets and call it a day
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.