Python Forum
sending data to second python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending data to second python script
#2
I stripped some unnecessary stuff from the example to make it easier to follow. I will have another look at whether it can be stripped down even more (the tornado and thread stuff), but I tested it like this and it runs from my pi (which is good).

import random
from time import sleep, time
from tornado import gen
from functools import partial
from concurrent.futures import ThreadPoolExecutor
from threading import Lock, Thread

from bokeh.layouts import column
from bokeh.models import ColumnDataSource
from bokeh.document import without_document_lock
from bokeh.plotting import figure, curdoc

t0=time()

executor = ThreadPoolExecutor(max_workers=2)
doc = curdoc()
@gen.coroutine
def update_data(x,y1,y2):
	new_data=dict(t = [x], tarTemp = [y1], temp = [y2])
	data.stream(new_data, 10000)


@gen.coroutine
@without_document_lock
def main():
	while True:
		doc.add_next_tick_callback(partial(update_data, x=time()-t0, y1=random.randint(0,100), y2=random.randint(0,100)))
		sleep(1)


data=ColumnDataSource(dict(t=[], tarTemp=[], temp=[]))
fig=figure(logo=None)
fig.xaxis.axis_label = 'Time (s)'
fig.line(source=data, x='t', y='tarTemp', line_width=2, alpha=.85, color='pink')
fig.line(source=data, x='t', y='temp', line_width=2, alpha=.85, color='purple')


doc.add_root(fig)
thread = Thread(target=main)
thread.start()
# start from console with	bokeh serve bokehtest.py --allow-websocket-origin=yourIP:5006
# and use a browser to look at yourIP:5006
Reply


Messages In This Thread
sending data to second python script - by Cyberfly - Jan-27-2018, 06:45 PM
RE: sending data to second python script - by Cyberfly - Jan-29-2018, 10:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending a text from Python sawtooth500 2 281 Apr-14-2024, 01:56 PM
Last Post: sawtooth500
  Sending data from the form to DB quisatz 5 1,429 Sep-27-2023, 04:58 PM
Last Post: quisatz
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,456 Jun-29-2023, 11:57 AM
Last Post: gologica
  script to calculate data in csv-files ledgreve 0 1,156 May-19-2023, 07:24 AM
Last Post: ledgreve
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,268 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  Help Sending Socket Data snippyro 0 1,083 Sep-23-2021, 01:52 AM
Last Post: snippyro
  Sending string commands from Python to a bluetooth device Rovelin 13 9,758 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  get data (temperature and humidity) from DHT22 into CSV and sending them over the net apollo 0 3,906 Apr-16-2021, 07:49 PM
Last Post: apollo
  Refresh data in python script while running in Terminal frankenchrist 4 7,438 Feb-03-2021, 09:54 AM
Last Post: Larz60+
  Sending Out Email via Python JoeDainton123 1 4,830 Aug-31-2020, 12:54 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020