-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added client/server from #491 to demos
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
"""Shows expected behavior for a client when the remote thread serving this client is busy/sleeping. | ||
Additional context: https://github.com/tomerfiliba-org/rpyc/issues/491#issuecomment-1131843406 | ||
""" | ||
import rpyc | ||
import threading | ||
import time | ||
|
||
|
||
def async_example(connection): | ||
t0 = time.time() | ||
print(f"Running async example...") | ||
_async_function = rpyc.async_(connection.root.function) | ||
res = _async_function(threading.Event()) | ||
print(f"Created async result after {time.time()-t0}s") | ||
value = res.value | ||
print(f"Value returned after {time.time()-t0}s: {value}") | ||
print() | ||
|
||
|
||
def synchronous_example(connection): | ||
t0 = time.time() | ||
print(f"Running synchronous example...") | ||
value = connection.root.function(threading.Event()) | ||
print(f"Value returned after {time.time()-t0}s: {value}") | ||
print() | ||
|
||
|
||
if __name__ == "__main__": | ||
connection = rpyc.connect("localhost", 18812, config=dict(allow_public_attrs=True)) | ||
async_example(connection) | ||
synchronous_example(connection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python | ||
"""Emulates a service function that is blocked due to being busy/sleeping. | ||
Additional context: https://github.com/tomerfiliba-org/rpyc/issues/491#issuecomment-1131843406 | ||
""" | ||
import rpyc | ||
import threading | ||
import time | ||
|
||
|
||
class Service(rpyc.Service): | ||
def exposed_function(self, event): | ||
threading.Thread(target=event.wait).start() | ||
time.sleep(1) | ||
threading.Thread(target=event.set).start() | ||
return 'silly sleeps on server threads' | ||
|
||
|
||
if __name__ == "__main__": | ||
rpyc.ThreadedServer(Service(), hostname="localhost", port=18812).start() |