Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

The Fool posted:

The benefit is to be able to develop in an environment as close to production as possible.

Yeah, I'm the one constantly preaching that idea on this very forum.

However, I don't think its necessary for a python application. A python 3.7 interpreter is a python 3.7 interpreter. The one inside your docker container is not going to have different behavior from the one in your virtualenv. Maybe I can see it if you're on windows and you're deploying to linux, but even thats a stretch.

I would, however, have CI tests that tests your whole docker-compose (or k8) infrastructure.


The Fool posted:

You also wouldn't develop "inside a container", you'd either push your code through vc and a hook would bring it in to docker, or your dev docker configuration would have a volume pointing at your code on your workstation.

Then what's all this talk about using a remote interpreter / remote debugging with pycharm?

Adbot
ADBOT LOVES YOU

shrike82
Jun 11, 2005

Docker is compelling if your application has non-python dependencies, and your team uses heterogeneous, potentially shared, development machines

My particular use case requires GPU access and we have a hierarchy of dev machines - from MacBook Pros/Linux gaming laptops to in-house multi-GPU linux servers to AWS GPU instances. Docker papers over the various hardware setups. It also allows for pretty fine-grained isolation, down to exposing individual GPUs to a given instance, so this helps a lot with maximizing usage of the in-house servers.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

shrike82 posted:

Docker is compelling if your application has non-python dependencies, and your team uses heterogeneous, potentially shared, development machines

My particular use case requires GPU access and we have a hierarchy of dev machines - from MacBook Pros/Linux gaming laptops to in-house multi-GPU linux servers to AWS GPU instances. Docker papers over the various hardware setups. It also allows for pretty fine-grained isolation, down to exposing individual GPUs to a given instance, so this helps a lot with maximizing usage of the in-house servers.

Yeah, this makes sense.

Loezi
Dec 18, 2012

Never buy the cheap stuff

shrike82 posted:

Docker is compelling if your application has non-python dependencies, and your team uses heterogeneous, potentially shared, development machines

Or depends on some weird academic research code that takes four days to flip a 50-50 coin to determine it'll run on this laptop or not and you can't find the time to rewrite the ancient thing because it would take half a yearbut is not publishable because it's not "novel" and ...

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I was thinking the same thing, but I don't know alot about docker. My python deployments are pretty much provider provisioning w/ user data -> sdist -> scp -> ssh tar xf && pip install. But I have some crazier packages with c where it would make sense to get more familiar with docker, if not just for the sake of getting with the times.

shrike82 posted:

Docker is compelling if your application has non-python dependencies, and your team uses heterogeneous, potentially shared, development machines

My particular use case requires GPU access and we have a hierarchy of dev machines - from MacBook Pros/Linux gaming laptops to in-house multi-GPU linux servers to AWS GPU instances. Docker papers over the various hardware setups. It also allows for pretty fine-grained isolation, down to exposing individual GPUs to a given instance, so this helps a lot with maximizing usage of the in-house servers.
This is pretty slick. I have some ML stuff using EGL, and it would be 100% less of a pain in the dick to sort this out with docker.

dougdrums fucked around with this message at 07:05 on Apr 9, 2019

Hollow Talk
Feb 2, 2014
Counterpoint: one of my coworker insists on using separate Vagrant machines for different projects, running them on Windows. In theory, Docker would be better here. However, the real downside is that he doesn't use virtualenvs because of it (and wouldn't with Docker, either). Unfortunately, some of the servers we use for ETL are provisioned by customers, so you get a funny mix of Windows Server, and various Linux distributions. But since he's not used to using virtualenv, he just loving installs everything globally. I told him to use virtualenvs on one of the servers, so he did. Next thing he deployed on the same loving server? Installed packages globally.

This wouldn't happen if he just used virtualenvs, which are good enough in most cases and even work on lovely half-maintained Windows Servers that we RDP to via two intermediate virtual desktops. I want to take his virtual machines away. Badly.

Also, just use Linux for development, ffs.

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Trying to install python-tcod on a Linux Mint 18 machine and run into this error when I run "pip3 install tcod":

code:
Command "/usr/local/bin/python3 -u -c "import setuptools, tokenize;
__file__='/tmp/pip-install-5h2mafwy/tcod/setup.py';f=getattr(tokenize, 'open', open)
(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))"
 install --record /tmp/pip-record-n9d0gjib/install-record.txt --single-version-externally-managed
 --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-5h2mafwy/tcod/
Pretty much everything I google up says "oh you need the python devtools installed" or "you need to update gcc", both of which I've done to no avail. I know that the error code it's giving is linked to GCC but the only things I'm finding relating to this are... again, insuring I have gcc/g++ updated. I do have python3-dev installed but it's saying it's version 3.5 - I've tried installing tcod with both python3 (3.7) and python3.5 (... 3.5). Am I missing something horribly simple? I can't get it installed in a virtual environment, either.

death cob for cutie fucked around with this message at 20:28 on Apr 9, 2019

Dominoes
Sep 20, 2007

I'm trying to repro a bug using docker and it's been a true PITA. Docker's rubbing me the wrong way, STS. Multiple unauthorized reboots, BIOS setting changes, ghost servers running long-deleted code etc. Don't care it's popular - this isn't polite behavior. Don't like.

Dominoes fucked around with this message at 21:08 on Apr 9, 2019

shrike82
Jun 11, 2005

Dominoes posted:

I'm trying to repro a bug using docker and it's been a true PITA. Docker's rubbing me the wrong way, STS. Multiple unauthorized reboots, BIOS setting changes, ghost servers running long-deleted code etc. Don't care it's popular - this isn't polite behavior. Don't like.

That's pretty unusual...

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
Stay safe ghost server

Data Graham
Dec 28, 2009

📈📊🍪😋



Caching at the edge server, survey says ...

Hadlock
Nov 9, 2004

Dominoes posted:

I'm trying to repro a bug using docker and it's been a true PITA. Docker's rubbing me the wrong way, STS. Multiple unauthorized reboots, BIOS setting changes, ghost servers running long-deleted code etc. Don't care it's popular - this isn't polite behavior. Don't like.

Unsure how to say this but sounds like a PEBKAC to me

Maybe we should do a containers thread, your ghost servers sounds like lack of familiarity with the system.... multiple reboots? Are you running this on windows or something?

the yeti
Mar 29, 2008

memento disco



Hadlock posted:


containers thread

If there’s not one it could probably be pretty useful

Hadlock
Nov 9, 2004

I may write up an OP for one here later this week. Watching developers gently caress around with "dockers" is like a sweaty nerd trying to figure out how to finger bang an unlucky girl in the back of a car for the first time

...probably need a love line thread for them

We have a devops thread but it's overly broad and generic

The Fool
Oct 16, 2003


Hadlock posted:

I may write up an OP for one here later this week. Watching developers gently caress around with "dockers" is like a sweaty nerd trying to figure out how to finger bang an unlucky girl in the back of a car for the first time

...probably need a love line thread for them

We have a devops thread but it's overly broad and generic

I think a docker/container specific thread would be a good idea. The topic has come up quite a bit in the last week across multiple IT and dev threads.

Data Graham
Dec 28, 2009

📈📊🍪😋



I'd totally sub it.

I still can't get my head around how volumes work and really what a container even is, like obviously it's not an entire VM image, it's like ... just a single app within an image, and you can have like 5-6 of them docker-composed together in the same environment, like one is your database and the other is your python app, but if you ssh into one it's like a parallel universe where it can't see any of the other ones and the db in the python env will be out of sync with whatever is in the db container? But in prod it all just magically works?

I mean I'm being deliberately obtuse here for effect but I do really wish I had a more visceral understanding of the concepts involved. Really sucks when you're having the guy who hired you explain it to you for the third time and you're watching his face fall as he comes to grips with the idea that he's made a huge mistake *Sound of Silence plays*

breaks
May 12, 2001

I don’t know much about containers and so take this with a grain of salt, but as a general concept roughly I think you can think of it as virtualization of the OS rather than virtualization of the hardware.

breaks fucked around with this message at 18:58 on Apr 10, 2019

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Data Graham posted:

I'd totally sub it.

I still can't get my head around how volumes work and really what a container even is, like obviously it's not an entire VM image, it's like ... just a single app within an image, and you can have like 5-6 of them docker-composed together in the same environment, like one is your database and the other is your python app, but if you ssh into one it's like a parallel universe where it can't see any of the other ones and the db in the python env will be out of sync with whatever is in the db container? But in prod it all just magically works?

I mean I'm being deliberately obtuse here for effect but I do really wish I had a more visceral understanding of the concepts involved. Really sucks when you're having the guy who hired you explain it to you for the third time and you're watching his face fall as he comes to grips with the idea that he's made a huge mistake *Sound of Silence plays*

Containers are easy to understand if you understand python because containers are an OS level namespace and as we all know :

quote:

Namespaces are one honking great idea -- let's do more of those!

Linux provides a method (see the unshare command)to separate processes, networking, etc into its own namespace just like how you can variables/functions/objects in their own namespaces (modules, classes, global, function) in python.

Linux also provides a method for limiting the resources (CPU, etc) available to a namespace (see cgroups).

Now, build a bunch of scripts around those two concepts, and all of a sudden you've got Docker containers!

Containers are what you call the conceptual thing you get when you smash namespaces and resource limiting by namespace together with a bunch of scripts.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
I use a NodeJS site interfacing with Flask to send commands to my Python script. The Python script is on multiple VMs and the NodeJS site is in one central
location. When I am running the Python script on some VMs, it outputs the following. This isn't consistent across the VMs though with some of them doing their thing In silence. I assume this is a setting somewhere given the Python is all identical.

code:
192.168.1.21 - - [10/Apr/2019 20:28:16] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:18] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:20] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:22] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:24] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:26] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:28] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:30] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:32] "GET /log HTTP/1.1" 200 -
192.168.1.21 - - [10/Apr/2019 20:28:34] "GET /log HTTP/1.1" 200 -

Hadlock
Nov 9, 2004

The Fool posted:

I think a docker/container specific thread would be a good idea. The topic has come up quite a bit in the last week across multiple IT and dev threads.

Ok I'll start one

I have some good resources for understanding containers at the kernel cgroup level plus some other stuff. Whatever I'm light on others can fill in the details

Sad Panda
Sep 22, 2004

I'm a Sad Panda.

Sad Panda posted:

I use a NodeJS site interfacing with Flask to send commands to my Python script. The Python script is on multiple VMs and the NodeJS site is in one central
location. When I am running the Python script on some VMs, it outputs the following. This isn't consistent across the VMs though with some of them doing their thing In silence. I assume this is a setting somewhere given the Python is all identical.

Fixed it. Werkzeug logging needed tweaking.


Next question...

Do people find that inner functions are a good idea?
I'm cleaning up my code and notice that in some of my classes there are functions which are only called from inside other functions in that class. They seem to logically belong to them. What downsides do inner functions have? The only one I can think of is that if you decide that you need to access them directly then you'd have to refactor.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

They're fine if they make sense.

Mostly I use them for closures or function factories, but sometimes it makes sense just from a code organization point of view.

There is a slight performance cost since a new function object is created every time the parent function is called.

Just for ease of reading I will sometimes pull them out if they get too long as it gets harder to read because the indentation level can get hard to keep track of. If I do pull it out and it's not used anywhere else, I'll probably slap a hyphen on the front of whatever name I give it just to have an indication that it's private.

QuarkJets
Sep 8, 2008

I never use inner functions. I dislike how they look. Function definitions in global scope only, likewise for class methods.

I also never use lambdas. They always look inelegant, to my eyes

necrotic
Aug 2, 2005
I owe my brother big time for this!
Lambdas in python are purposefully awful which is unfortunate.

Loezi
Dec 18, 2012

Never buy the cheap stuff
Today I learned about https://docs.python.org/3/library/contextlib.html#contextlib.suppress and
Python code:
with suppress(FileNotFoundError):
    os.remove('somefile.tmp')
Are there other similar useful context managers, other than open, that one wouldn't necessary know about?

susan b buffering
Nov 14, 2016

Loezi posted:

Today I learned about https://docs.python.org/3/library/contextlib.html#contextlib.suppress and
Python code:
with suppress(FileNotFoundError):
    os.remove('somefile.tmp')
Are there other similar useful context managers, other than open, that one wouldn't necessary know about?

Basically anything where you're dealing with a resource that should eventually be released can use it. Off the top of my head, sqlite connections, thread Locks, and socket servers all can make use of the "with" statement, which is essentially shorthand for the traditional try-finally block that you would use to ensure an open resource is released when it is no longer needed.

In more concrete terms, any object which implements the __enter__ and __exit__ methods is a context manager, and will work with "with".

susan b buffering fucked around with this message at 09:47 on Apr 13, 2019

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

Loezi posted:

Today I learned about https://docs.python.org/3/library/contextlib.html#contextlib.suppress and
Python code:
with suppress(FileNotFoundError):
    os.remove('somefile.tmp')
Are there other similar useful context managers, other than open, that one wouldn't necessary know about?

Is that the same thing as doing a try/except: pass?

E: it is. Shoulda read the link.

Boris Galerkin fucked around with this message at 09:53 on Apr 13, 2019

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Writing context managers and decorators for your own concepts is good and fun.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

For example, I'm writing a thing now that abstracts away different backends that mostly have the same API, but not exactly.

For this one function all these backends take a parameter `handle` as an int value...except one which takes the int parameter as a specifically formatted string.

So, my code works like this:

I have an abstract base class that the wrapper class for each backend inherits from and implements all the abstract methods.

So, a method in the abstract base class might look like this:

Python code:
  @abc.abstractmethod
  def get_title(self, handle: int) -> str: ...
The implementation in the wrapper for this one weird backend looks like this:

Python code:
  @i_r_a_weirdo
  def get_title(self, handle: int) -> str:
    # blah blah blah
And a rough sketch of my decorator for handling this weirdo backend:

Python code:
def i_r_a_weirdo(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        func_sig = inspect.signature(func)
	
        args, kwargs = convert_weirdo_args(func_sig, args, kwargs)

        return func(*args, **kwargs)

    return wrapper
So now, I can always pass ints like a sane person. It's a nice way of DRY-ing the code that I'd have to write in every method in this wrapper for the weirdo backend that takes this handle parameter.

I like writing these things.

larper
Apr 9, 2019
I wanna get better at Django. Anyone got a solid tutorial they would like to share?

I set up a Django CMS like 2 months ago, I forget most of what I learned. I remember the virtualenv stuff but not much else.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
I have my script running on a variety of VMs. I'm trying to work out a way to update them all centrally through a command. I've got a requirements.txt and if I'm on the machine can just go to the command prompt and do a pip install -r requirements.txt which works perfectly. I tried to automate this with the following line of code.

Python code:
        result = subprocess.run(args=['pip', 'install', '--user', '-r', self.requirements_file])
This seems to work just fine. I'm just curious if there's a better way to do this? Someone on the Python Discord suggested "look into pipenv" but unless that has huge benefits then I'd rather not move to that as it sounds like I'd have to re-deploy the solution. If however it is worth it, then I'd rather get it done now before setting up more VMs.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

The Xkdc Larper posted:

I wanna get better at Django. Anyone got a solid tutorial they would like to share?

I set up a Django CMS like 2 months ago, I forget most of what I learned. I remember the virtualenv stuff but not much else.

The official tutorial is pretty good.

Really, the best way to get better at any framework is to make lots of stuff with it.

That being said, it sounds like maybe you need help with more than just django? virtualenv's are not just a django thing...

unpacked robinhood
Feb 18, 2013

by Fluffdaddy

It may be overkill but I think this is a common Ansible use case.

Hollow Talk
Feb 2, 2014

Sad Panda posted:

I have my script running on a variety of VMs. I'm trying to work out a way to update them all centrally through a command. I've got a requirements.txt and if I'm on the machine can just go to the command prompt and do a pip install -r requirements.txt which works perfectly. I tried to automate this with the following line of code.

Python code:
        result = subprocess.run(args=['pip', 'install', '--user', '-r', self.requirements_file])
This seems to work just fine. I'm just curious if there's a better way to do this? Someone on the Python Discord suggested "look into pipenv" but unless that has huge benefits then I'd rather not move to that as it sounds like I'd have to re-deploy the solution. If however it is worth it, then I'd rather get it done now before setting up more VMs.

Use pssh to run this in parallel on multiple machines.

unpacked robinhood posted:

It may be overkill but I think this is a common Ansible use case.

I think this might be overkill unless Ansible is already in use. If you already use Ansible, by all means, do this.

PBS
Sep 21, 2015
Clustershell is also pretty nice.

Umbreon
May 21, 2011
Which version would be better to start learning if I wanted to get into python? v2 or v3?

QuarkJets
Sep 8, 2008

3 almost without a doubt; you get tons of great new features and performance improvements, and even programmers of 2 are encouraged to use the future module to make their code compatible with 3 because everyone is expected to upgrade **eventually**

2 if you're working with a bunch of people who are still using 2 and refuse to update to 3

Hadlock
Nov 9, 2004

3 unless you have very specific reasons to be using 2 at this point. Kind of like asking if you should run Windows XP or Windows 10

Umbreon
May 21, 2011
Noted. Thanks guys, I'm gonna give codecademy a try and see how things roll. I've never actually coded/programmed anything before but it always bothered me that I just assumed I couldn't do it without actually giving learning it a fair shake.

Adbot
ADBOT LOVES YOU

Neslepaks
Sep 3, 2003

Test mocking question.

I have a module that i have to mock wholesale, by patching sys.modules.

This works but in my code i have an except modulename.ExceptionName and I can't figure out how to trigger it. I've put an exception of the same name in my mock object but I'm assuming the namespacing is wrong at the time it runs because it never catches. Ideas?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply