Tomer,
Thank you very much for the response and wonderful package. It really
should become part of the python standard library. :-)
The approach you outlined seems to be for classic mode.
I also came up with another approach for new style services: making the
service class data members *static* (by defining them prior to the function
definitions in the service class). This way their values are available to
to be "shared" among different connections.
For example:
class MyService(rpyc.Service):
answer = 1
def on_connect(self):
pass
def on_disconnect(self):
# code that runs when the connection has already closed
# (to finalize the service, if needed)
pass
def exposed_get_answer(self): # this is an exposed method
return MyService.answer
def exposed_set_answer(self, answer):
MyService.answer = answer
MyService.answer, now a static class data member, can be set by one client
(say to the value of 5 via a conn.root.set_answer(5) call) and that value
(of 5) can be read back by the next client/connection (by a
conn2.root.get_answer() call). Naturally, proper concurrent programming
controls/practices would need to be implemented in real usage.
Bart
On Saturday, March 28, 2015 at 10:06:22 PM UTC-7, Tomer Filiba wrote:
>
> That's not persistency, that's global state. Each connection has its own
> state, but you can use global state as well, via modules, for example. E.g.
>
> conn1.modules.__main__.foo = 5
> print conn2.modules.__main__.foo
>
> If you want to persist the data, just pickle it on the server and load it
> again when you restart, or have the first client do that
> On Mar 29, 2015 4:35 AM, "Bart Bortnik" <[email protected] <javascript:>>
> wrote:
>
>> Hello,
>>
>> Can objects on the server be persistent? In other words, if one
>> connection changes the value of an integer and then disconnects, can a
>> second connection connect and read the value of the integer that was
>> assigned by the first connection?
>>
>> It seems like objects are not persistent. To test, I created a
>> ThreadedServer and then connected two clients to the server. The Service
>> sublcass had an "exposed" function that sets and gets a simple a integer
>> variable. The first client set the value to 5. The second client however
>> did not read the value 5.
>>
>> How do I make it so that both clients are able to access the *same*
>> object/value?
>>
>> Thanks,
>> Bart
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "rpyc" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
---
You received this message because you are subscribed to the Google Groups
"rpyc" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.