@scrypted/server 0.7.6 → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @scrypted/server might be problematic. Click here for more details.
- package/dist/plugin/media.js +1 -1
- package/package.json +1 -1
- package/python/plugin_remote.py +38 -12
- package/src/plugin/media.ts +1 -1
package/dist/plugin/media.js
CHANGED
@@ -331,7 +331,7 @@ class MediaManagerBase {
|
|
331
331
|
node[candidateId] = inputWeight + outputWeight;
|
332
332
|
}
|
333
333
|
catch (e) {
|
334
|
-
console.warn(
|
334
|
+
console.warn(candidate.name, 'skipping converter due to error', e);
|
335
335
|
}
|
336
336
|
}
|
337
337
|
// source matches
|
package/package.json
CHANGED
package/python/plugin_remote.py
CHANGED
@@ -8,6 +8,7 @@ import platform
|
|
8
8
|
import shutil
|
9
9
|
import subprocess
|
10
10
|
import threading
|
11
|
+
import concurrent.futures
|
11
12
|
import time
|
12
13
|
import traceback
|
13
14
|
import zipfile
|
@@ -35,6 +36,21 @@ class SystemDeviceState(TypedDict):
|
|
35
36
|
value: any
|
36
37
|
|
37
38
|
|
39
|
+
class StreamPipeReader:
|
40
|
+
def __init__(self, conn: multiprocessing.connection.Connection) -> None:
|
41
|
+
self.conn = conn
|
42
|
+
self.executor = concurrent.futures.ThreadPoolExecutor()
|
43
|
+
|
44
|
+
def readBlocking(self, n):
|
45
|
+
b = bytes(0)
|
46
|
+
while len(b) < n:
|
47
|
+
self.conn.poll()
|
48
|
+
b += os.read(self.conn.fileno(), n - len(b))
|
49
|
+
return b
|
50
|
+
|
51
|
+
async def read(self, n):
|
52
|
+
return await asyncio.get_event_loop().run_in_executor(self.executor, lambda: self.readBlocking(n))
|
53
|
+
|
38
54
|
class SystemManager(scrypted_python.scrypted_sdk.types.SystemManager):
|
39
55
|
def __init__(self, api: Any, systemState: Mapping[str, Mapping[str, SystemDeviceState]]) -> None:
|
40
56
|
super().__init__()
|
@@ -467,14 +483,17 @@ class PluginRemote:
|
|
467
483
|
|
468
484
|
async def getFork():
|
469
485
|
fd = os.dup(parent_conn.fileno())
|
470
|
-
|
486
|
+
reader = StreamPipeReader(parent_conn)
|
487
|
+
forkPeer, readLoop = await rpc_reader.prepare_peer_readloop(self.loop, reader = reader, writeFd = fd)
|
471
488
|
forkPeer.peerName = 'thread'
|
472
489
|
async def forkReadLoop():
|
473
490
|
try:
|
474
491
|
await readLoop()
|
475
492
|
except:
|
493
|
+
# traceback.print_exc()
|
476
494
|
print('fork read loop exited')
|
477
|
-
|
495
|
+
finally:
|
496
|
+
reader.executor.shutdown()
|
478
497
|
asyncio.run_coroutine_threadsafe(forkReadLoop(), loop=self.loop)
|
479
498
|
getRemote = await forkPeer.getParam('getRemote')
|
480
499
|
remote: PluginRemote = await getRemote(self.api, self.pluginId, self.hostInfo)
|
@@ -563,13 +582,15 @@ class PluginRemote:
|
|
563
582
|
async def getServicePort(self, name):
|
564
583
|
pass
|
565
584
|
|
566
|
-
async def plugin_async_main(loop: AbstractEventLoop, readFd: int, writeFd: int):
|
567
|
-
peer, readLoop = await rpc_reader.prepare_peer_readloop(loop, readFd, writeFd)
|
585
|
+
async def plugin_async_main(loop: AbstractEventLoop, readFd: int = None, writeFd: int = None, reader: asyncio.StreamReader = None, writer: asyncio.StreamWriter = None):
|
586
|
+
peer, readLoop = await rpc_reader.prepare_peer_readloop(loop, readFd=readFd, writeFd=writeFd, reader=reader, writer=writer)
|
568
587
|
peer.params['print'] = print
|
569
588
|
peer.params['getRemote'] = lambda api, pluginId, hostInfo: PluginRemote(peer, api, pluginId, hostInfo, loop)
|
570
589
|
|
571
590
|
async def get_update_stats():
|
572
591
|
update_stats = await peer.getParam('updateStats')
|
592
|
+
if not update_stats:
|
593
|
+
return
|
573
594
|
|
574
595
|
def stats_runner():
|
575
596
|
ptime = round(time.process_time() * 1000000)
|
@@ -601,10 +622,14 @@ async def plugin_async_main(loop: AbstractEventLoop, readFd: int, writeFd: int):
|
|
601
622
|
|
602
623
|
asyncio.run_coroutine_threadsafe(get_update_stats(), loop)
|
603
624
|
|
604
|
-
|
605
|
-
|
625
|
+
try:
|
626
|
+
await readLoop()
|
627
|
+
finally:
|
628
|
+
if reader and hasattr(reader, 'executor'):
|
629
|
+
r: StreamPipeReader = reader
|
630
|
+
r.executor.shutdown()
|
606
631
|
|
607
|
-
def main(readFd: int, writeFd: int):
|
632
|
+
def main(readFd: int = None, writeFd: int = None, reader: asyncio.StreamReader = None, writer: asyncio.StreamWriter = None):
|
608
633
|
loop = asyncio.new_event_loop()
|
609
634
|
|
610
635
|
def gc_runner():
|
@@ -612,10 +637,10 @@ def main(readFd: int, writeFd: int):
|
|
612
637
|
loop.call_later(10, gc_runner)
|
613
638
|
gc_runner()
|
614
639
|
|
615
|
-
loop.run_until_complete(plugin_async_main(loop, readFd, writeFd))
|
640
|
+
loop.run_until_complete(plugin_async_main(loop, readFd=readFd, writeFd=writeFd, reader=reader, writer=writer))
|
616
641
|
loop.close()
|
617
642
|
|
618
|
-
def plugin_main(readFd: int, writeFd: int):
|
643
|
+
def plugin_main(readFd: int = None, writeFd: int = None, reader: asyncio.StreamReader = None, writer: asyncio.StreamWriter = None):
|
619
644
|
try:
|
620
645
|
import gi
|
621
646
|
gi.require_version('Gst', '1.0')
|
@@ -624,17 +649,18 @@ def plugin_main(readFd: int, writeFd: int):
|
|
624
649
|
|
625
650
|
loop = GLib.MainLoop()
|
626
651
|
|
627
|
-
worker = threading.Thread(target=main, args=(readFd, writeFd), name="asyncio-main")
|
652
|
+
worker = threading.Thread(target=main, args=(readFd, writeFd, reader, writer), name="asyncio-main")
|
628
653
|
worker.start()
|
629
654
|
|
630
655
|
loop.run()
|
631
656
|
except:
|
632
|
-
main(readFd, writeFd)
|
657
|
+
main(readFd=readFd, writeFd=writeFd, reader=reader, writer=writer)
|
633
658
|
|
634
659
|
|
635
660
|
def plugin_fork(conn: multiprocessing.connection.Connection):
|
636
661
|
fd = os.dup(conn.fileno())
|
637
|
-
|
662
|
+
reader = StreamPipeReader(conn)
|
663
|
+
plugin_main(reader=reader, writeFd=fd)
|
638
664
|
|
639
665
|
if __name__ == "__main__":
|
640
666
|
plugin_main(3, 4)
|
package/src/plugin/media.ts
CHANGED
@@ -385,7 +385,7 @@ export abstract class MediaManagerBase implements MediaManager {
|
|
385
385
|
node[candidateId] = inputWeight + outputWeight;
|
386
386
|
}
|
387
387
|
catch (e) {
|
388
|
-
console.warn(
|
388
|
+
console.warn(candidate.name, 'skipping converter due to error', e)
|
389
389
|
}
|
390
390
|
}
|
391
391
|
|