mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-12-25 17:49:45 +05:30
temporary fix for #25
Uses multithreading.Process instead of GLib.timeout_add() The moment I finished writing this part, I found out the only problem with my previous commit was that I had setup the timeout _after_ calling the blocking function wait_for_change instead of before it. Although this version (with Process) works, I'm reverting to the previous version and swapping the two lines (which I had tested and found to work) And in case you have read upto the previous line you should also know I fixed some code in the README TL;DR: I have proven once again I am an idiot
This commit is contained in:
parent
d7a84d8ccc
commit
5e58df0b71
@ -136,7 +136,7 @@ uname -r
|
||||
python3 --version
|
||||
|
||||
# Check for IBSS (ad-hoc) support in your WiFi firmware or driver
|
||||
iw phy | grep -iq ibss && echo "IBSS is supported" || echo "IBSS not supported"
|
||||
iw phy | grep -q join_ibss && echo "IBSS is supported" || echo "IBSS not supported"
|
||||
```
|
||||
|
||||
Clone the naxalnet repo and cd into it.
|
||||
@ -300,8 +300,9 @@ systemd-networkd configures the network.
|
||||
|
||||
### Online class
|
||||
|
||||
naxalnet can be used to share connections to join online classes.
|
||||
You need at least one device with internet access if you are not using a program like [Jami][].
|
||||
naxalnet can be used to share connections to join online classes. You need
|
||||
at least one device with internet access if you are not using a program
|
||||
like [Jami][].
|
||||
|
||||
<!--
|
||||
|
||||
|
@ -42,4 +42,4 @@ given below.
|
||||
#
|
||||
# In case you forgot to change the version, skip the number
|
||||
# and put the next number in the next commit.
|
||||
__version__ = "0.5.1a0.dev5"
|
||||
__version__ = "0.5.1a0.dev6"
|
||||
|
@ -28,9 +28,10 @@ examples.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from multiprocessing import Process
|
||||
from pathlib import Path
|
||||
from dasbus.connection import SystemMessageBus
|
||||
from dasbus.loop import EventLoop, GLib
|
||||
from dasbus.loop import EventLoop
|
||||
|
||||
|
||||
NETWORKD_BUS = "org.freedesktop.network1"
|
||||
@ -142,6 +143,7 @@ class NetworkLoop(NetworkD):
|
||||
self.waitfor = None
|
||||
self.wait_function = None
|
||||
self.loop = EventLoop()
|
||||
self.timeout = 0
|
||||
|
||||
def start_loop(self):
|
||||
"""start the dasbus loop"""
|
||||
@ -149,17 +151,30 @@ class NetworkLoop(NetworkD):
|
||||
print("waitfor", self.waitfor)
|
||||
print("waitfor func", self.wait_function)
|
||||
self.proxy.PropertiesChanged.connect(self.on_properties_changed)
|
||||
self.loop.run()
|
||||
process = Process(target=self.loop.run)
|
||||
process.start()
|
||||
|
||||
# wait until timeout
|
||||
if self.timeout != 0:
|
||||
process.join(self.timeout)
|
||||
else:
|
||||
process.join()
|
||||
|
||||
# When the process is timed out, it is not killed. We have to kill
|
||||
# it manually
|
||||
if process.is_alive():
|
||||
self.on_timeout()
|
||||
|
||||
def wait_until_routable(self, timeout=0):
|
||||
"""
|
||||
Wait until timeout in milliseconds and returns True when any
|
||||
Wait until timeout in seconds and returns True when any
|
||||
network interface is shown routable by networkd. Does not wait
|
||||
for timeout if timeout==0
|
||||
"""
|
||||
print("wait until routable")
|
||||
self.timeout = timeout
|
||||
self.wait_for_change("AddressState", self.on_addressstate_change)
|
||||
self.setup_timeout(timeout)
|
||||
|
||||
return self.is_routable()
|
||||
|
||||
def wait_for_change(self, name, function):
|
||||
@ -181,13 +196,7 @@ class NetworkLoop(NetworkD):
|
||||
if self.waitfor in data:
|
||||
return self.wait_function()
|
||||
|
||||
def setup_timeout(self, timeout):
|
||||
"""setup a timeout"""
|
||||
print("setup timeout")
|
||||
if timeout != 0:
|
||||
GLib.timeout_add(timeout, self.on_timeout)
|
||||
|
||||
def on_timeout(self):
|
||||
"""called by dasbus when a timeout occurs"""
|
||||
"""called when a timeout occurs"""
|
||||
print("on timeout")
|
||||
self.loop.quit()
|
||||
|
@ -63,8 +63,7 @@ def any_interface_is_routable():
|
||||
logger.debug("Adding temporary config %s", i)
|
||||
networkd.add_config(i)
|
||||
|
||||
# timeout = 10 seconds
|
||||
routable = networkd.wait_until_routable(10 * 1000)
|
||||
routable = networkd.wait_until_routable(timeout=10)
|
||||
networkd.remove_all_configs()
|
||||
|
||||
return routable
|
||||
|
@ -1,3 +1,4 @@
|
||||
[build-system]
|
||||
# I don't know what this means, I just copied it from some setuptools tutorial
|
||||
requires = ["setuptools", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
@ -1,4 +1,7 @@
|
||||
# This program is not meant to be distributed through PyPi
|
||||
# This file is loosely based on the setup.cfg used in django.
|
||||
# naxalnet is not meant to be distributed through PyPi. This program uses
|
||||
# a systemd service, and some other files whose path is hardcoded into the
|
||||
# module.
|
||||
[metadata]
|
||||
name = naxalnet
|
||||
version = attr: naxalnet.__version__
|
||||
|
Loading…
Reference in New Issue
Block a user