How do I make my async coroutine function not block?

I’m trying to write some concurrent Python.

In my app below, I’m trying to subscribe to a websocket feed, but then continue through the app, so this code should just print hello. Instead, it blocks on feed.__init__.

I’m hoping I can build a websocket client to some update some application state.

How do I do feed.__init__ and continue running my program, while the websocket runs in the background?

def main():
  myFeed = feed('XBTUSD')
  while True:

import websockets
import asyncio
import json

class feed:
    def __init__(self, symbol):
        self.symbol = symbol
        self.uri = "wss://,quote:{}".format(symbol)
        # asyncio.get_event_loop().run_forever()

    async def socket(self):
      async with websockets.connect(self.uri) as websocket:
        while True: 
          msg = await websocket.recv()

    def process_msg(self, msg):
        data = msg['data'][0]
        if data['symbol'] == self.symbol:
            self.last_message = msg 


Go to Source
Author: cjm2671

Choosing between DI (without container) and Composition

I’m working on a classes that are designed to read a defined file format; said format is comprised of 2 separate files (FileA and FileB). For ease of use, the format is referred to as the FileA format, but a valid “file” must have a FileB. The files share the same path prefix, but alter in suffix; therefore my current classes appears as:

class FileReaderA:
    def __init__(self, path: pathlib.Path):
            self.a = path.with_suffix('.fa')
            self.b = FileReaderB(path)
    # methods related to operating on FileA types

class FileReaderB:
    def __init__(self, path: pathlib.Path):
            self.b = path.with_suffix('.fa')
    # methods related to operating on FileB types 

The classes are separated since FileReaderB does not depend on FileReaderA and can be used independently to read FileB types, however a valid FileA requires its associated FileB. Therefore, composition made sense, at first. Now I’m wondering if DI is the more appropriate solution, but it requires that FileReaderB be explicitly instantiated and passed to the constructor of FileReaderA, which is less than ideal form a user standpoint with this API:

>>> frb = FileReaderB(path)
>>> fra = FileReaderA(path, frb)

Thus I am forced to abstract it by using a factory:

def reader(path: pathlib.Path):
    return FileReaderA(path, FileReaderB(path))

>>> fra = reader(path)

This seems verbose and I feel as though I’m introducing more code and layers of abstraction to achieve the same result, all around the guise for better unit testing of decoupled classes.

What is wrong with just using Composition over enforcing DI?

Go to Source
Author: pasta_sauce

How to stylize the EqualTo Validator message in Flask?

I have the validator

EqualTo('pass_confirm', message='Passwords Must Match!')

which when the passwords don’t match shows an error like this.

How do I stylize the error message to be red? I’ve already tried changing the message to a <span style="color:red">, but it renders plain text and not the HTML.

enter image description here

Go to Source
Author: Alex F

Flask setup using SSL and subdomain on Ubuntu server

I’m am new to Flask and trying to set up a flask webpage on the subdomain I have another webpage running on that has nothing to do with this flask app.

When I enter “service apache2 reload” and try to go on it just gives me this:
Error when trying to view webpage

The main website (just a plain HTML) on looks like this:

Image of main website working

My config file looks like this:


Listen 443
<IfModule mod_ssl.c>

        <VirtualHost *:443>

                ServerAdmin webmaster@localhost

                DocumentRoot "/home/bhelpful/html"

                SSLEngine on
                SSLCertificateFile "/etc/ssl/bhelpful_net.crt"
                SSLCertificateKeyFile "/etc/ssl/private/bhelpful_net.key"


        <VirtualHost *:443>

                ServerAdmin webmaster@localhost
                WSGIScriptAlias / /home/ohl/ohl.wsgi
                <Directory /home/ohl/Online-Help-List/app/>
                        Order allow,deny
                        Allow from all

                Alias /static /home/ohl/Online-Help-List/app/static/
                <Directory /home/ohl/Online-Help-List/app/static/>
                        Order allow,deny
                        Allow from all

                ErrorLog ${APACHE_LOG_DIR}/FlaskApp-error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/FlaskApp-access.log combined

                SSLEngine on
                SSLCertificateFile "/etc/ssl/bhelpful_net.crt"
                SSLCertificateKeyFile "/etc/ssl/private/bhelpful_net.key"



# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The WSGI file looks like this:


import sys
import logging

from app.help_me import app as application

The main flask file lays here:

Treeview of files and folders

Go to Source
Author: Andreas G.D Petersen

Remove rows of one Dataframe based on one column of another dataframe

I got two DataFrame and want remove rows in df1 where we have same value in column ‘a’ in df2. Moreover one common value in df2 will only remove one row.




Go to Source
Author: Sarim Nabi

In example 1 how 11 came? please anyone explain

I calculated permutation and all but i am not getting how to calculate this 11 Please Help.
Single Lane Highway
Problem Description
Certain number of cars are passing a single lane road. Speeds of all cars vary. It is easy to see, that depending on the speeds of the cars various groups will be formed.

Being a single lane road passing/overtaking is not allowed. Given speeds of cars, calculate how many groups can be formed if all possible permutations are taken into account. Refer example1 for better understanding.

Print number of groups divided by the number of permutations.

0 <= N < 10 ^ 5

0 <= speed of individual vehicle < 10 ^ 9

First line contains an integer N, which denotes the number of vehicles

Second line contains N space separated integers which denotes the speed of individual vehicle.

Print number of groups divided by the number of permutations rounded upto 6 decimal places.

Time Limit
Example 1



10 20 30




So all possible permutations are:

{10 20 30}

{10 30 20}

{20} {10 30}

{20 30} {10}

{30} {10 20}

{30 20} {10}

So here there are total 6 permutations, and total number of groups are 11.

So, output is 11/6 = 1.833333

Example 2



56 78 13 92




So here there are total 24 permutations,

For example:

{56 78 13 92}

{92} {13 78 56}

{56} {13 92 78}

{78 92} {13 56}



So on and so forth. The total number of groups are 50.

So, the output is 50/24 = 2.083333

Go to Source
Author: Abhinav Shukla

Pattern design for a trading application

Do you know how trading sites/applications manage data and then display it?
e.g. prorealtime, tradingview, metatrader etc.
From our side, we receive raw data or already processed data that are just displayed?

I don’t understand why you down vote my post.
What is the difference with this kind of question?
Why does Java use :: for method references instead of .?

Is maintenance, feedback, or support an integral phase of SDLC?

They just ask questions

Go to Source
Author: antho

tktinter proplem i need anyone to enter sory for the bad title

i want to put text beside every entry but it prints all texts and entrys on one row i want to use the pack method to print every entry with a text line every one one on a row and i want full code please

from tkinter import *
root = Tk()
l1 = Label(root, text="Name")
name = Entry(root)
l2 = Label(root, text="age")
age = Entry(root)
l3 = Label(root, text="color")
color = Entry(root)
l4 = Label(root, text="number")
number = Entry(root)
l1.pack(side = LEFT)
name.pack(side = RIGHT)
l2.pack(side = LEFT)
l3.pack(side = LEFT)
color.pack(side = RIGHT)
l4.pack(side = LEFT)
number.pack(side = RIGHT)
root = mainloop()

Go to Source
Author: marwan azzam

Delete duplicated words in the same row in Pandas

i’m pretty new to Python Pandas and to programming. I have a dataframe that looks something like this (just a simplified example):

   A      B  
0  name1  Dog, Dog, Cat
1  name2  Dog, Bird
2  name3  Cat, Cat, Cat
3  name4  Dog, Cat, Bird

I want to delete the duplicated values on each row, so my DataFrame looks like this:

       A      B  
0  name1  Dog, Cat
1  name2  Dog, Bird
2  name3  Cat
3  name4  Dog, Cat, Bird

I saw that I can do something like that with from collections import OrderedDict, but as I said I’m pretty new to programming, and I have no idea how to do that. It would be great if you could help me, thank you!

Go to Source
Author: David Masnou Sánchez

Trying to figure out running multiple queries with single endpoint based on the input parameters

I am trying to create a system, which has multiple queries for different kinds of reports. My plan is to queries in the database tag them report A, report B. Obvisouly SQL query will have some placeholders to pass paramterers.

I am trying reduce my coding work. So that i’ll keep adding queries in the database without touching the code.

i have explored diffrent django tool, but i haven’y found any suitable tool.

Any guidence will be apperictaed.

Go to Source
Author: wizard

interrogating this html element to retrieve value

im using selenium chromedriver to automate the filling in of a form. the last step is copying the final price. when i try to get text from the element i receive nothing.

below is a picture of the element in question. i want to pull a price from it.

[picture of problem][1]

these lines:

print("read this")

gives this output:

read this


Total Rental
excl. VAT
 <div class="col-sm-4 label-col"> <label for="TotalRegularPayment" class="ng-binding">Total Rental</label> </div> <div class="col-xs-10 col-sm-6 input-col"> <div class="input-group currency"> <span class="input-group-addon calculator-addon disabled-style" ng-class="{'disabled-style': ($ctrl.field.meta.is_read_only || $ctrl.isLockedDown)}"><currency-symbol class="ng-isolate-scope"><span class="ng-binding">£</span></currency-symbol></span> <input id="TotalRegularPayment" name="TotalRegularPayment" sr-money-focus-clear="" sr-money-value="" class="mousetrap form-control ng-pristine ng-untouched ng-valid ng-not-empty" tabindex="1" type="text" ng-model="$ctrl.field.value" ng-change="$ctrl.onChange()" ng-disabled="($ctrl.field.meta.is_read_only || $ctrl.isLockedDown)" disabled="disabled"> <!-- ngIf: $ctrl.field.meta.show_vat_label --><span class="input-group-addon vat-placeholder ng-binding ng-scope disabled-style" ng-if="$ctrl.field.meta.show_vat_label" ng-class="{'disabled-style': ($ctrl.field.meta.is_read_only || $ctrl.isLockedDown)}"> excl. VAT </span><!-- end ngIf: $ctrl.field.meta.show_vat_label --> </div> </div> <div class="col-xs-2 col-sm-2 text-center"> <sr-calculating-spinner field="$ctrl.field" calculator-id="$ctrl.calculatorId" on-calculate="$ctrl.calculate()" class="ng-isolate-scope"><!-- ngIf: $ctrl.field.meta.is_calculable && !$ctrl.quoteModel.is_quote_read_only --> <!-- ngIf: $ctrl.model.calculation_path === $ && $ctrl.model.is_calculating --></sr-calculating-spinner> </div> 

the element i want is total price but i also printed its wrapper to see if i got anything useful i didnt.
could you please advise on how i could print the price.

Go to Source
Author: tgm_jack_uk