Comments (4)
As a workaround I'm able to do the following:
from mcipc.query import Client
import signal
def check_players_online(host: str, port: int) -> bool:
def _timeout_handler(signum, frame):
raise Exception("Minecraft server did not reply in time")
signal.signal(signal.SIGALRM, _timeout_handler)
signal.alarm(1) # Should be instant since the server is at localhost
with Client(host, port) as client:
print(client.basic_stats)
signal.alarm(0)
return client.basic_stats.num_players > 0
However this won't necessarily work in multithreaded or non-UNIX environments.
from mcipc.
The Rcon an Query clients use python's socket
library.
You should be able to set timeouts as described in the socket library's documentation:
https://docs.python.org/3/library/socket.html#socket-timeouts
PS: I added an additional optional timeout parameter to the Rcon and Query clients:
f7c2a3c
from mcipc.
The new timeout paramater works perfectly. Thanks for the fix!
For future reference, my new usage looks as follows:
def check_players_online(host: str, port: int) -> bool:
with Client(host, port, timeout=1) as client:
print(client.basic_stats)
print(f"{client.basic_stats.num_players} player(s) are online")
return client.basic_stats.num_players > 0
from mcipc.
Glad, I could help. I'm always interested in providing new features.
As for your use case, you might want to have a look at mcipc's own rconclt
(which, however uses RCON, not Query), and especially at rconclt <server> in-use
and rconclt <server> idle-shutdown
.
from mcipc.
Related Issues (20)
- use of built in types for Type hints HOT 2
- Can not install via pip "No matching distribution found for mcipc" HOT 3
- I can't run the example program HOT 4
- TypeError: cannot convert 'NoneType' object to bytes HOT 3
- Linux Bug HOT 2
- Doesn't work anymore HOT 5
- Client.stats() (as depicted in readthedocs) refuses to work HOT 2
- Converting into dict() HOT 2
- Bedrock? HOT 3
- Python 3.8 HOT 1
- is async supporting? HOT 1
- TypeError: 'TypeVar' object is not callable HOT 2
- Long responses from commands are truncated and break the connection HOT 25
- Parsing NBT HOT 2
- Changes to behaviour of Item HOT 6
- I'm having problems creating the code HOT 1
- ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it HOT 1
- An existing connection was forcibly closed by the remote host HOT 3
- Error while attempting to run a command using RCON on a Minecraft Bedrock Server HOT 2
- Circular import error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mcipc.