Re: How/where to store calibration values - written by program A, read by program B

Liste des GroupesRevenir à cl python 
Sujet : Re: How/where to store calibration values - written by program A, read by program B
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 28. Dec 2023, 12:38:37
Autres entêtes
Organisation : Stefan Ram
Message-ID : <scripts-20231228120252@ram.dialup.fu-berlin.de>
References : 1 2 3
rbowman <bowman@montana.com> writes:            Assuming both scripts are
running, how does the change get propagated to B after it is set in A and
written to the shared file?

  I don't think it was intended to be written to the file,
  just to the module in memory. But it does not work here
  under CPython.

  config.py

value = None

  sender.py

import config
import itertools
import time

for i in itertools.count():
    config.value = i
    time.sleep( 1 )

  receiver.py

import config
import time

while True:
    print( config.value )
    time.sleep( 1 )
  
  output

None
None
None

  I tried it with sockets. But due to my lack of experience with
  sockets, it might be more complicated and erroneous than necessary!
  It needs some more work before it can be used in a product.

  receiver.py (start this one first)

import socket as socket_module

server = socket_module.socket()
server.bind( ( '127.0.0.1', 58962 ))
server.listen()
client, address = server.accept()
result = b''

while True:
    while len( result )< 128 and b'\r\n' not in result:
        result += client.recv( 128 )
    while b'\r\n' in result:
        txt, result = result.split( b'\r\n', 1 )
        if txt:
            print( int( txt ))

client.close()

  sender.py

import itertools
import socket as socket_module
import time

socket_module.setdefaulttimeout( 5 )

socket = socket_module.socket()
socket.connect( ( '127.0.0.1', 58962 ))
for i in itertools.count():
    socket.send( bytes( str( i ), encoding='ASCII' ) + b'\r\n' )
    time.sleep( 1 )
socket.close()

  output

0
1
2



Date Sujet#  Auteur
28 Dec 23 * Re: How/where to store calibration values - written by program A, read by program B2Stefan Ram
28 Dec 23 `- Re: How/where to store calibration values - written by program A, read by program B1Stefan Ram

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal