#๐Ÿ”’ How do i make a ping function?

107 messages ยท Page 1 of 1 (latest)

warm valve
#

Like, print the response time in milliseconds

fair masonBOT
#

@warm valve

Python help channel opened

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.

warm valve
#

like this;
?ping
Pong! Response: {ms}

lime cosmos
#

is this for a discord bot?

warm valve
#

nope

#

this is for LCP (a project that i'm working on)

#

like a command panel like a terminal

#

hello guys???

#

@lime cosmos

lime cosmos
#

Im gonna need some more context

warm valve
#

like what? ask me

lime cosmos
#

wait so is this like matrix calculations

warm valve
#

aw man i want to know how to make this function so badly

lime cosmos
#

wait do u mean LCP array?

warm valve
#

LCP lanzoor command panel

#

;-;

lime cosmos
#

what would you be pinging to get the latency then?

warm valve
wheat urchin
#

whats an LCP

lime cosmos
#

since this is a local program if you ping nothing there will be no latency

lime cosmos
#

this probably

#

they are making their own command panel thingy

wheat urchin
#

so you want latency but.... it's a command panel?

warm valve
#

well yes

lime cosmos
#

yeah what are you trying to get the latency for

warm valve
#

;-;

wheat urchin
#

latency of what

warm valve
#

i just want the response time

lime cosmos
#

I'm so confused

#

response time is zero since there is no networking involved

unborn cliff
#

so you essentially want to replicate ping command from system that returns the latency between a server and a client

wheat urchin
#

latency basicallt means response time

#

see ping gets the time it takes like a server to respond to something

lime cosmos
#

idk maybe just import os

#

and then when they use the ping command

#
os.system("ping google.com")```
warm valve
lime cosmos
#

for some cool stuff

wheat urchin
unborn cliff
lime cosmos
#

are you trying to time print()?

warm valve
#

github ๐Ÿ˜‚ i gues

warm valve
wheat urchin
#

๐Ÿ’€ ๐Ÿ™

warm valve
#

is it just 0?

wheat urchin
#

practically 0 yes

lean nacelle
#

uh

unborn cliff
#

most local operations do not have a latency that you'd need to worry much about (like print)

lean nacelle
#

what are you trying to ping

warm valve
lean nacelle
#

wtf

wheat urchin
#

theres no point ๐Ÿ˜ญ

warm valve
#

even though it is 0 it can still be something else

lean nacelle
#

why

lime cosmos
#

!epy import time now = time.time() print("this is a test") after = time.time() time_taken = after - now print(time_taken)

#

ok

warm valve
#

if you have a potato computer

lime cosmos
#

im dumb

wheat urchin
dusk grove
#

time.time

wheat urchin
warm valve
#

...ok

#

then pinging github it is

lime cosmos
#

!e py import time now = time.time() print("this is a test") after = time.time() time_taken = after - now print(time_taken)

fair masonBOT
#

@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
unborn cliff
lime cosmos
lime cosmos
#

I guess

unborn cliff
wheat urchin
#

!d timeit

fair masonBOT
#

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.

wheat urchin
#

built in

warm valve
#

oh actually thats it

#

lol thx

#

wait is this millisecond or second?

wheat urchin
#

that's seconds

lime cosmos
#

seconds

wheat urchin
#

effectively 0

warm valve
#

ok

unborn cliff
#

0.2 ms lol

wheat urchin
#

this is so pointless ๐Ÿ˜ญ

lime cosmos
#

yeah milliseconds is multiply by 1000

lean nacelle
#

Why doing this

wheat urchin
#

forreal

static root
#

print is more likely going to be IO-bound too

unborn cliff
# lean nacelle Why doing this

(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)

warm valve
warm valve
unborn cliff
#

it is kinda useless for print and input unless you are working on cpython internals or something

dusk grove
unborn cliff
#

ngl i'd connect using sockets and call it a day

warm valve
#

ok imma close this

#

!close

fair masonBOT
#
Python help channel closed

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.