import logging from django.conf import settings from services.cores.decorators import expect_parameters from services.cores.command_based_service_base import CommandBasedServiceBase LOGGER = logging.getLogger('bloom.services.CalculatorService') class CalculatorService(CommandBasedServiceBase): def init(self): self.expect_initialisation_from(websocket=True) @expect_parameters('num_a', 'num_b') def command_calculate_sum(self, message): try: self.send_client_flow_message('SUM_VALUES_OK', {'result': float(message['num_a']) + float(message['num_b'])}) LOGGER.info("Sum calculated and result transmited sucessfuly.") except Exception as e: LOGGER.error("Error in sum calcutalion or result transmission.") if settings.DEBUG: self.send_client_flow_message('ERROR_CALCULATING_SUM', {'error': "{}".format(e)})
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question