mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-11 10:44:21 +02:00
i3-companion: handle correctly unconnected polybar sockets
It's the `open()` call which is blocking, not the `write()`. Use `os.open()` instead.
This commit is contained in:
parent
51fe9fff00
commit
0f2b12e228
1 changed files with 7 additions and 17 deletions
|
@ -6,7 +6,6 @@ import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
import collections
|
||||||
import errno
|
import errno
|
||||||
import fcntl
|
|
||||||
import functools
|
import functools
|
||||||
import glob
|
import glob
|
||||||
import html
|
import html
|
||||||
|
@ -467,7 +466,7 @@ async def network_manager_status(i3, event, *args):
|
||||||
return
|
return
|
||||||
network_manager_status.running = None
|
network_manager_status.running = None
|
||||||
try:
|
try:
|
||||||
await network_manager_status__now()
|
await _network_manager_status_now()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("while updating network status: %s", str(e))
|
logger.warning("while updating network status: %s", str(e))
|
||||||
if network_manager_status.running is None:
|
if network_manager_status.running is None:
|
||||||
|
@ -475,7 +474,7 @@ async def network_manager_status(i3, event, *args):
|
||||||
network_manager_status_now(5)
|
network_manager_status_now(5)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def network_manager_status__now():
|
async def _network_manager_status_now():
|
||||||
status = []
|
status = []
|
||||||
|
|
||||||
# Build status from devices
|
# Build status from devices
|
||||||
|
@ -532,7 +531,6 @@ async def network_manager_status(i3, event, *args):
|
||||||
|
|
||||||
if status != last:
|
if status != last:
|
||||||
logger.info(f"network status: {status}")
|
logger.info(f"network status: {status}")
|
||||||
network_manager_status.last = status
|
|
||||||
|
|
||||||
# Update cache file (for when polybar restarts)
|
# Update cache file (for when polybar restarts)
|
||||||
with open(
|
with open(
|
||||||
|
@ -543,22 +541,14 @@ async def network_manager_status(i3, event, *args):
|
||||||
# Send it to polybar's module/network
|
# Send it to polybar's module/network
|
||||||
for name in glob.glob("/tmp/polybar_mqueue.*"):
|
for name in glob.glob("/tmp/polybar_mqueue.*"):
|
||||||
try:
|
try:
|
||||||
with open(name, "w") as out:
|
with open(os.open(name, os.O_WRONLY | os.O_NONBLOCK), "w") as out:
|
||||||
# Switch to non-blocking mode. If process on
|
|
||||||
# the other side is dead, we get an ENXIO.
|
|
||||||
# Buffer should ensure we don't block
|
|
||||||
# otherwise.
|
|
||||||
fd = out.fileno()
|
|
||||||
old_flags = fcntl.fcntl(fd, fcntl.F_GETFL)
|
|
||||||
fcntl.fcntl(
|
|
||||||
fd, fcntl.F_SETFL, old_flags | os.O_NONBLOCK
|
|
||||||
)
|
|
||||||
|
|
||||||
cmd = f"action:#network.send.{status}"
|
cmd = f"action:#network.send.{status}"
|
||||||
out.write(cmd)
|
out.write(cmd)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENXIO:
|
if e.errno != errno.ENXIO:
|
||||||
pass
|
raise
|
||||||
|
|
||||||
|
network_manager_status.last = status
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isinstance(event, DBusSignal)
|
isinstance(event, DBusSignal)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue