« first day (4063 days earlier)      last day (868 days later) » 

5:29 AM
cbg guys
 
cbg
 
 
4 hours later…
9:15 AM
there is something ironic about my pc crashing while I want to fill a bug report
 
We encountered an unexpected bug while filing your bug report. Please file a bug report for the bug encountered while filing a bug report using our bug reporting software.
 
9:49 AM
Given a slice object, is there an easy way to figure out the largest index this slice will access? I can't use the indices() method because I don't know the length
(I'm writing a list-like container that lazily calculates its contents on demand, and I need to figure out how many additional items I need to compute)
 
You can use the isclice pseudocode as a recipe to convert a slice into a range.
The last index would be slice_range[-1].
my_slice.indices(sys.maxsize) could be equivalent for getting the start/stop/step of the range.
 
That doesn't support negative indices/step sizes though, does it?
 
Both of these should work for negative indices/step as well.
 
I'm feeling kinda silly, but I'm adding a print statement between all lines where some code freezes. It doesn't throw an exception it just doesn't continue. Is there a good way to debug that, with a debugger and without a bunch of print statements?
 
pdb is a good step up from print. Andras linked to some even better debugger with dark mode a few days ago as well.
 
10:03 AM
I guess I could add a bunch of break points and just click next until it freezes
that sounds more reasonable
 
I'm a fan of print statements, though. :P
 
boost.org/doc/libs/1_75_0/libs/range/doc/html/range/reference/… LOL, I read that boost combine gives UB if the input vectors are not of the same length, I had two thoughts when reading this 1. This is for sure gonna happen to me 2. This is for sure not gonna happen to me because I'm gonna make sure the inputs are correct, thus I don't need to check for it. Isn't it amazing how our brain can think both 1 and 2 which are opposites at the same time :D
I guess 1 is some kind of recursive estimator taking into account the past experiences with similarly difficult problems and 2 is the future projecting wishful part of the brain :D
 
@Aran-Fey I don't get it, there's no well-defined max index without a length, right?
 
There's math.inf :D
 
just taking slice(None), this will always give you length - 1
I'm just saying I don't understand your premise
your lazy list-like container should have a concept of length, otherwise lstish[-1] would make no sense
 
10:14 AM
There can't be any indices bigger than sys.maxsize, so that's an upper bound at least.
 
@MisterMiyagi pudb
theming is the main point, but it also has things like a variable explorer and code exploration :P
 
It will always have a place in my heart as the "dark mode debugger".
Lately I have been playing with Cython and manually declared headers/cdef extern. It's the good feeling of driving without training wheels all over again!
 
@MisterMiyagi Can not confirm
>>> class S:
...     def __getitem__(self, index):
...         return index
...
>>> S()[sys.maxsize + 99999:]
slice(9223372036854875806, None, None)
 
I suspect that your problem can be solved exactly when max(range(some_length)[slice]) works.
 
@Aran-Fey Well, you can get lucky and hit a path that isn't checked, but I would not recommend it. Many parts will blow up with such indices.
Do you really have a use-case that needs more than sys.maxsize items? Those are a lot.
 
10:26 AM
I honestly can't figure out how to do this, and maybe I explained my goal poorly, so for reference, here is my current attempt + some test cases
@MisterMiyagi Probably not, but I'd rather not write code with an arbitrary limit
 
so it looks like your cases are
1. not a slice
2. slice with known nonzero start and stop
3. slice with missing or negative start and stop
1. is not a slice, 3. is float(inf)
I'm not sure about the practical difference between inf and sys.maxsize. Both of these mean that you can't be lazy with your list.
I'm probably also missing why you're doing this
 
TIL: range has no optimisation for max...
 
whoah
how the heck
ah, max is a separate function call, it just sees an iterable
I guess max doesn't have an optimization for range
 
I was expect a __max__ dunder...
 
silly old bear
 
10:39 AM
If you can live with the maxsize restriction, this should work:
def required_length(index):
    if isinstance(index, slice):
        indices = range(*index.indices(sys.maxsize))
        return 0 if not indices else indices[-1] + 1 if indices.step > 0 else indices[0]
    else:
        return index + 1 if index > 0 else sys.maxsize
I wouldn't give it extra points over manually calculating things, though.
 
Nested conditional expressions? Where's my slapping trout...
 
Notice: Code snippets may contain subliminal educational content.
 
@MisterMiyagi That fails a bunch of my (new) tests:
# input       expected output: actual output
slice(5, 3, -1)           6  : 5    FAIL
slice(8, 3, -4)           9  : 8    FAIL
slice(3, -5, -1)          inf: 0    FAIL
slice(-5, -3, -1)         inf: 0    FAIL
 
Off-by-Miyagi error:
6 - 1 == 5
9 - 1 == 8
inf - 1 == 0
I love it that the slice.index method is very well hidden, took me long enough to find it even though I knew it exists.
also the anchors are crazy in the docs, ugh
 
10:58 AM
@Aran-Fey Actually, the result for slice(-5, -3, -1) should indeed be 0
 
I'm still not sure why slice(3, -5, -1) should be inf while we are at it. :P
 
or 0
 
Hmm, you're right. It actually should be 8. As long as the list has less than 8 elements, [3:-5:-1] can return a non-empty list. But starting at a length of 8, that slice becomes empty. So my list only needs to contain 8 elements for that to produce the correct result.
>>> list(range(6)[3:-5:-1])
[3, 2]
>>> list(range(8)[3:-5:-1])
[]
 
Can we just agree that slices are complicated and Aran should give up whatever project he's working on?
And PSA: advent of code starts tomorrow
4
 
Hahaha, I'm glad I have a concrete problem like this to solve, rather than continue to fret about design decisions like I have for the past 2 weeks
 
11:13 AM
@AndrasDeak Yes to the first, no to the second. I'm still caught in morbid fascination...
Practical solution: forbid negative indices.
 
Actually, aren't those "highest index" calculations inaccurate when there's a partial step to the end?
 
That's what isclice does and it seems that your use-case is close enough to "lazy iterators" to fit in the same category.
 
or is that good enough for a heuristic?
 
Y'all gonna be caught by surprise when this exact problem shows up on AoC day 1 and I laugh at you with my 2 day head start muahahahaha
 
hehe
 
11:30 AM
@Hakaishin you could use the trace module (already installed). If you want it to print it's output to specific file you'd have to modify it (I did it on mine) to do this.
python3 -m trace -m -t yourpythonfile
 
@Hakaishin add a breakpoint before the problem, then step instead of continue. You'll get one line after the other. c continues to next breakpoint, n steps to next line, s "step into" i.e. goes into the next function call, if memory serves.
this is what debuggers are for
 
yeah, breakpoint are really useful too. Never used it as much as trace though but that's probably because I'm used to debug shell scripts this way
 
@AndrasDeak yeah, I had a drunken moment, that's what I did afterwards
 
11:52 AM
hello guys, anyone here know how to use this answer without async def stackoverflow.com/questions/64379089/…
I get ValueError: [TypeError("'coroutine' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')] if I use in a def function
 
what code did you write to get that?
 
its the same thing, I just removed async
 
did you remove await or no
 
I dont want to have a async route cuz I have blocking functions, but I need the json body, that is my ask
@ParitoshSingh yes I did
 
Does FastAPI even have non-async routes?
 
11:55 AM
i believe it should
 
it does
I am using fastapi.tiangolo.com/async and it has some def routes
 
id say think along the lines of debugging what the actual issue is. are you actually getting a json on the json call or a coroutine?
 
I did it! Only took 90 lines of code!
 
to phrase it differently, that block of code seems simple and innocent to me, so removing async and await keyword "should have been" enough. so, just investigate the issue
check datatypes, check your assumptions.
 
The docs for the Request type indicate that all those fields are async.
 
12:00 PM
this is my entire code
from fastapi import FastAPI, Request

app = FastAPI()

@app.post("/index")
def index(request: Request):
    return request.json()
 
you used a fastapi Request.. that thing is async then. .json doesnt give a json until you await.
 
@MisterMiyagi ohh, so there is no way I can get the request body or json in sync?
@ParitoshSingh yes, that brings to my original question, what should I change?
 
i dont know async syntax, but you should be able to think of this as effectively "how do i run async code from sync code" and theres usually answers like loop until complete or stuff like that.
 
tbh I just stackoverflow.com/a/16664376/16962446 but in Fastapi lol
 
i wont know specifics, but your problem boils down to "get actual json from the thing that -would have- given a json"
you could also probably just.. not use Request
and find a substitute for it thats sync. this is just a guess on my part
 
12:07 PM
yeah, thats what I am googling, thought you guys might know
 
FastAPI uses anyio, so you should be able to use its thread interface to run blocking code inside async functions.
 
@Aran-Fey i have no idea what's going on, but why is 3 giving 4..i suppose i dont know the original question well enough to understand what just happened.
 
If you want to access index 3, the list must have a length of 4
 
oh
gotcha
 
@MisterMiyagi I guess I could do this, if I can not find a way to get the json, thanks a bunch
 
12:19 PM
the whole reason for this is because I can not use aiohttp from fastapi, it gives me ssl error
but the aiohttp call works if i directly call it using plain asyncio python
for those who are interested
import asyncio
import aiohttp
from fastapi import FastAPI, Request

app = FastAPI()

@app.post("/index")
async def index(request: Request):
    return await google()

async def google():
    async with aiohttp.ClientSession() as session:
        async with session.get('https://google.com') as response:
            return await response.text()

# print(asyncio.run(google()))
the last print does not give me the error, but calling from the route gives me the error
so i just dumped aiohttp and call it with requests and it works
 
12:32 PM
I went ahead and created a question, if anyone is interested feel free to answer stackoverflow.com/questions/70169406/…
 
I am moderately interested, but I know little about SSL
 
that is still more interest for someone who is not directly involved with the problem :D
I am 90% ok with an answer that explains why, cuz if I push this, my boss is going to ask me why I snuck in some ssl stuff, which for some reason feels like a hack
 
Understandable
Poking around the dependencies... fastapi.tiangolo.com/tutorial/#install-fastapi is interesting, don't think I've ever seen a pip install command that uses square brackets
 
all these async stuff has these, flask 2.0, aiohttp
idk how pip works, but I am seeing this in async libraries
 
FastAPI is really struggling to install itself on my computer. It has complained of Cargo, the Rust package manager, is not installed or is not on PATH. about a dozen times now. It appears to be trying to install every version of orjson starting with 3.8 and moving backwards. It's at 3.3.0 now.
 
12:47 PM
I'm guessing this is a duplicate ...? stackoverflow.com/questions/70167806/…
 
2.6.8... I really thought it would have given up at 3.0.0
 
@Kevin you can try the minimal installation, I dont think my code uses everything it needs
 
Good idea
How do I do a minimal installation? My wild guess is pip install "fastapi[minimal]" but I can't try it until orjson gives up
 
you dont use the [] thing
just fastapi
 
Thanks
It finally ended at orjson-2.0.7. I commend pip for its bloody-minded persistence, if nothing else
 
12:54 PM
I was sending my positive vibes to you :D
 
That's an error message you don't see every day: ValueError: generator already executing
 
Ok, I think I got it set up. If I start the server with uvicorn main:app --reload, and go to http://127.0.0.1:8000/docs#/default/index_index_post in my browser, and click the Try It Out button, I get a 200 response, and about 15k bytes worth of HTML that looks like it might be from Google.
 
I do the same exact thing, I get Internal Server Error
in the terminal I get the ssl error
 
My terminal says ←[32mINFO←[0m: 127.0.0.1:63070 - "←[1mPOST /index HTTP/1.1←[0m" ←[32m200 OK←[0m. I'm pretty sure those square brackety bits may be ignored, it's just style information that cmd doesn't understand
 
it could probably understand them if you used colorama. But then again, colorama only have support for a small subset of ascii escape code, compared to what's hidden in win32 undocumented api (it has full support for linux though)
 
1:06 PM
let me try this on a different computerr
 
I do have colorama pip-installed, but ofc it won't do anything unless uvicorn imports and inits it
 
you are right Kevin, this only happens on my work issued laptop
 
For the record, my fastapi.__version__ is 0.52.0. Just in case this is a problem with recent versions
 
@Aran-Fey that's pretty cool
 
well mine is 0.70.0 on both :/ but it happens only on one
 
1:10 PM
I know that corporate laptops sometimes fiddle with host files and such in order to route web traffic for various purposes. For surveillance most likely, and perhaps performance reasons or authentication
 
if you're using a corporate vpn, that may also contribute to that not working
I vaguely recall of someone I know who worked for a local company remotely, and they had the worst openvpn setup if you ever saw one
 
@Kevin this seems to be the case
I did turn off my VPN
 
My own work laptop does something similar. On the sinister data collection scale, I give it 3 FBI surveillance vans out of 10.
 
the company I mentioned earlier also break your workflow completely every update they do to their "tracking app". By breaking, I mean stuff such as: disabling usb ports, blacklisting everything plugged (even keyboard)...
 
the thing that confuses me is, why am I not getting the error if I call this directly?
 
1:14 PM
they fix it each time it happen, but I think someone in their IT team is busy doing something else, probably
@Jake you mean you only get this error when you call it outside your terminal?
 
That also confuses me. I guess the two approaches are sending slightly different packets.
 
even if I run this at my work laptop the aiohttp standalone call works fine
@NordineLotfi I get this error if fastapi calls the function, if I have a normal python code that calls the function it is not there
 
I see. Then the problem is probably around the fastapi calls function hmm. Did you try using the trace module on it and looking at the output?
 
If all else fails, perhaps you could compare the packets in Wireshark
 
if you compare both output of trace from your work pc to the other one where it work
something might be noticeable
that too ^
python3 -m trace -m -t pythonfile
 
1:17 PM
@Kevin I will try this, seems kinda advanced for my current skillset, lets see how much I can go
will try the trace suggestion too now
@NordineLotfi so how do I this for fast api?
 
Yeah Wireshark can be a bit of a pain because by default it shows you everything that your computer is sending or receiving, and that's a lot even if it's sitting there with no windows open. Filtering out all the stuff you don't care about can take some doing
 
@Jake if you have the code in question in a file, just use the command I mentioned earlier, and compare it's output to the one of the other pc you said was working with fastapi
 
trace might not play nicely with the code here, since the error only occurs when uvicorn executes it
 
so pythonfile is main.py?
 
@Kevin oh, you're right. I didn't know about the specific of uvicorn (thinking it was just another third party python stuff)
@Jake yeah
 
1:26 PM
@NordineLotfi this gives me like 1000 lines and I stopped it
wireshark at least has a GUI lol
both seems way out of my league now
 
yeah, I admit that I suffered quite a bit when I first used trace but after a while, you get used to it (especially if you have time on your side)
I guess regex search also help quite a bit when you know what you want to investigate
 
anyways thanks all for helping me out, I will let you guys know if I find the cause of this, or if someone answers it :D
have a nice day / eve all
 
Apparently fastapi uses ssl.create_default_context to handle its ssl stuff... I wonder if it's possible to use that to see where the certificates are coming from.
 
1:42 PM
I typed "ssl" into the github search bar and it showed 0 results in the fastapi repo
 
RIP
 
Darn, foiled once more ;-)
 
or maybe you could use scapy? I never used it but I remember someone mentioning it could be used to filter/investigate packet (although probably slower than wireshark but that's beside the point)
 
I guess I can try this, even though I have 32 packets in the timeframe, I still dont know what to look at
 
I guess starting by: - what type of packet you have in those 32... - which one is coming from where? etc
from there a logic will begin to take form and you'll fly through
 
1:45 PM
Correction: aiohttp uses create_default_context. See docs.aiohttp.org/en/stable/client_reference.html. ctrl-F for "(ssl.create_default_context() is used)", because I couldn't find an anchor link for the request method or its parameters
Incidentally I think there are some parameters there that would let you skip SSL certification entirely, but caveat emptor
 
if I skip ssl, is that a good thing?
 
@Jake depends on context, but I have to regularly do it, because our network is not set up correctly. Ideally if you have time you go and talk to whoever manages the network, worst case you ignore it
 
this seems to be the thing I am missing uvicorn.org/settings/#https
 
I don't understand the specifics myself, but skipping ssl means that you lose out on a lot of the security benefits of HTTPS
 
@Hakaishin I can try this, but I am sure they wont allow if I even mention the slightest of disabling ssl
 
1:54 PM
Then you got your answer :)
You could do it, to be sure it's the ssl causing the issue and then activate it again and try to find a proper way to do it
 
That uvicorn setting does indeed look important
You might be able to find your certificates file using certmgr.msc... Not totally sure how that tool works
 
the certifi.where() in the code I have gives that, thank Stackoverflow :D
 
2:09 PM
Hello everyone. I've a question. Would it be possible, through python, to lock a file while it is being modified? By lock I mean, prevent any other process from consuming the file, until the writing is over.

I've tried Filelock:
https://stackoverflow.com/a/498505/10371713
but I am still able to open the file manually from File Manager, while it is supposedly locked.
(OS: linux)
 
@John did you try the other answer there? eg: stackoverflow.com/a/46407326/12349101
 
To be honest I did not. Just saw a lot of code and thought it must be simpler than that
 
Looks like that FileLock solution only works if everything trying to open the file is also using FileLock.
 
yeah. The answer I linked would probably work better since it depend on fcntl and such
 
@NordineLotfi I just checked the answer you mentioned. I already tried the solution from another SO question https://stackoverflow.com/a/32650956/10371713
but I can still open the file while it is being modified
 
2:17 PM
@John ah, that's weird then
 
I'm probably doing something wrong. Will investigate it more! Thank you : )
It seems like trying to access the file while it is being modified, it is overwritten and becomes empty
 
yeah, you're right; just tried it on my end (I'm on linux too)
 
@Kevin uvicorn.run('main:app', port=8000, ssl_ca_certs='path to cert') running uvicorn like this makes the issue go away, just wanted to ket you know :D, the command line arg still fails though
 
yeah, but honestly I don't know at this point, instead of adding it at a different place I am adding it here lol
 
2:23 PM
progress!
 
I am guessing the issue now narrows down to uvicorn not fastapi or aiohttp
 
@John oh, I know why; it's because of the part open(path, 'w'). but what's weird is that it's used on most implementation I seen, such as this. It seems like the lock attribute is indeed placed on the file, but as you noticed too, you can still open it and modify it by another process...this is weird
some variation I seen also contain wb instead, but because of w it still overwrite the file. Unless I'm being mistaken I think it's weird
 
b mode only changes the type of data returned by file.read, so it won't have any impact over locking
 
Yeah. I would expect an error or something that would prevent me from opening it
 
yeah, don't know why some implementation use it but that's one of the variation I seen
me too
 
2:36 PM
Some implementations use it because they want read to return a bytes object instead of a string. That's all it does
I think it's worthwhile to really conssider whether you need mandatory locking. Many of the use-cases of mandatory-locked files can be replicated with friendlier technology. For example, if you're trying to use a file to send messages between processes, then the subprocess module has ways to do that with no files involved.
 
yeah, and if you happen to want this because you want to prevent access to a file by external app (eg: outside of python) you could instead twist the logic a bit, and look for CLOSE_WRITE event on the file, using something like watchman or inotify, and then do X once that happen
 
I receive images via socket. These images are saved locally. However, I suspect that problem might occur if the consumer (i.e javascript accessing the file from a webserver) tries to read the image while python still writes the data to the image.

The result is a corrupted image
 
2:55 PM
@John hmm, found this. I guess this could work for your case (and would mimick a "file lock". Only thing to do is to find python equivalent of this
 
Will take a look at it. Thank you!
 
3:07 PM
Proposal: have Python write the data to imagename.png.partial. After writing is complete, rename the file to imagename.png. There should be no point where imagename.png contains only partially written image data.
 
@Kevin classic and time tested solution
 
another thing would be to keep the partial image in memory, but that would probably bite you later on if it become too big, unless you know the users using the app won't exceed X MB per image, and then discard the older ones as you load them/as they're ready on the disk
 
@Kevin Thank you for the suggestion. That indeed sounds a good and simple approach!
 
3:24 PM
btw, how can I add bytes to a list? not as integer ofc. The reason is because I got output from a socket implementation like this Client Sent: b'(874, 116)' <class 'bytes'> but other times, when the client is faster (eg: send too much data at once) or the reverse (client is slower/delayed, server is faster):
Client Sent: b'(750, 638)(746, 625)(745, 614)' <class 'bytes'>
I get something like this instead
 
Do you have to use sockets? That's horribly low-level technology. Can't you use something more high-level, like websockets?
 
You can add anything to a list using the_list.append, doesn't matter whether it's a bytes or not.
 
@Aran-Fey I don't have to, but I prefer to instead :) it's also easier for me since I'm used to it, and it's used in a specific workflow. eg: offline, through ssh tunnel (no paramiko support yet), etc
But I don't mind trying it if it's easier
 
>>> x = b'(750, 638)'
>>> the_list = []
>>> the_list.append(x)
>>> the_list
[b'(750, 638)']
 
@Kevin I see :o Thanks, I'll try this
 
3:28 PM
@NordineLotfi You need to use a protocol that defined how large messages are. Common approaches are fixed-length messages and length headers.
If that seems arcane, follow Aran's suggestion. Otherwise, follow Aran's suggestion.
 
It is definitely easier. I've never met a single person who wrote correct socket code. There are plenty of people who can do that, but the vast majority of people absolutely cannot.
 
I'd say even if you can it's usually just not worth it.
 
Yeah. The people who can write correct socket code avoid writing socket code like the plague, pretty much.
 
Alright. I don't mind relying/limiting it to 1024 as I already do with socket, since most of what I send won't be bigger than that, but thing is, I don't really want to install another deps/reqs for this current project (already made a concession with 3 modules).
also, pretty much everything I write, at least for now isn't really up to standard. So that won't change much in that effect
 
what would be the theoretical worst case time complexity of a procedure whose inputs are a list and a paramter k and sorts only the first k numbers in the list
 
3:35 PM
@NordineLotfi You should read through the Socket Programming HOWTO, then.
 
@MisterMiyagi already did actually (it's a pretty short read compared to other docs) :D
(and also less documented at that)
 
> the combination of sockets with INET makes talking to arbitrary machines around the world unbelievably easy
Ha! Talking to others? Easy. Understanding each other? Not so easy.
 
'Tis was a time of wonder and nerds spending ages in their garage.
 
@Aran-Fey yeah, but if you read through the whole thing, you'd notice that a lot of it will contradict that specific sentence
 
Not as clumsy or random as HTTP; an elegant tool for a more civilized age.
 
3:43 PM
also, whoever wrote that doc, for better or worse, like to do a lot of "interpersonal" talk/sentence, such as As long as you aren’t doing something dumb or In fact, on Windows I usually use threads (which work very, very well) with my sockets....It's a first for me in a python docs
 
Speaking of sockets, @Kevin, I tried the renaming solution you mentioned earlier, and the corrupted images are surely reduced but I still receive a few here and there.

My guess is that, there is probably data loss, since I receive them via socket. I wonder how is that possible though, as I use socket.socket(socket.AF_INET, socket.SOCK_STREAM). Isn't tcp supposed to provide data integrity?
 
there probably isn't data loss, but maybe, as my own case/problem, one side is faster or send more/less data then the other can accept it/work on it
this might create some weird side effect in your code eg: maybe whatever function handle either image chunk need a specific length or bytes that isn't there, etc
you can notice this easily if you use len and print statement
 
If your socket protocol makes it clear how long the total message is, and your server/client properly wait until it receives the total message before processing it, then there shouldn't be any corruption
 
yeah, this was just a guess since I only ever worked with non-image data with socket.
 
It won't matter if the receiver is a hundred times faster than the sender, because you'll have programmed it to patiently wait for the final byte before it acts
 
3:50 PM
yeah, but I don't think they mentioned using the final complete file or chunks (since if they used something like PIL, they could still work around chunked image)
 
Sounds hard. I recommend that the sender sends the file without doing anything fancy to its contents, and the receiver waits to receive the entire file before trying to work with it.
 
Thanks for your inputs. I wait until all image data arrive before writing them.
imgData = bytearray(b'')
while True:
tempData = bytearray(client.recv(1024))
imgData.extend(tempData)
if not tempData:
break
>Image data are ready here but still sometimes corrupted
Ah, indents disappeared
 
If it turns out that you desparately need to begin working on the first 10% of the image before the other 90% arrives, you can brainstorm cool streaming protocols then.
 
@MisterMiyagi this helped me built a minimal rsync clone for windows. It's was buggy as heck the first few months, but after that it worked :)
 
How can you tell the image is corrupted? Does it look funny in the image viewer? Does it refuse to open entirely? Something else?
If you send the same image multiple times, is it always corrupted in the same way?
 
4:00 PM
This is what I mean: ibb.co/PMyq1SC
 
Can you compare the file size of the corrupted image, and the file size of the original?
 
Yeah, the corrupted one is smaller
 
Hmm. How big is the corrupted one?
 
just making sure, but you're using PIL right? if not, which module you're using for handling image
(couldn't find which module extend refer to)
 
If all he's doing is accepting data from the socket and saving it to a file, then no image handling library is required
 
4:07 PM
Actually the observation that the corrupted file is smaller came after comparing the typical size of a correctly received image with the corrupted one
I don't have access to the images from the sending point right now
 
@Kevin oh, I thought there was since based on the example above, there was a extend function being used...
 
imgData is a bytearray. bytearray is a builtin type, albeit a rather obscure one
 
corrupted file I've sent you is ~500kb and typical correctly received file is always 1.2MB
 
Do you have the code that's doing the sending?
 
My crystal ball tells me that the other end of the connection is doing socket.send(data) instead of socket.sendall(data)
 
4:10 PM
@Kevin Yeah. It's android
 
I have a little experience with android. Can you put the code in a pastebin?
 
@John so it's a java app? and you made a java-python socket implementation?
 
So do I. java code is not mine. Will do it in a minute.
@NordineLotfi yeah
 
@Aran-Fey I'm breaking into a cold sweat, trying to remember how many of my own socket-based projects use send
 
4:15 PM
Thanks :-)
 
Maybe sleep time is not enough
I mean before closing the socket
 
My guess is that the sleep doesn't really matter. Once the client sends the data, it can disconnect or self-destruct or whatever, and the server will still be able to receive the data
I welcome you to keep it around anyway, if it gives you peace of mind. It's a scarce resource when doing network programming :-P
 
wait, what are you using to connect to the java socket: through adb (wifi, usb...) or something else?
 
hmm
@NordineLotfi I don't understand the question
There is an android app that sends images using a socket
And a python script that receives them
 
I'm asking this because most java-python socket implementation use something in between to connect, eg: adb (android debug bridge), or something else (websocket, wifi?, etc)
so it's through internet?
 
4:22 PM
yeah
well, local network
 
ah, if it was adb I would have a theory, but nvm
 
Anyway, I don't want to waste any more of your time. Thank you @Kevin @NordineLotfi for the help : )
 
That dos.write(data); call is odd, because it doesn't fit either of the type signatures documented at docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html
You can either call write(int), or write(byte[], int, int), but not write(byte[])
 
I guess seeing the import lists would help, since it's not included in the pastebin (maybe write is from a third party import)
 
Perhaps. If the DataOutputStream being used here is not a java.io.DataOutputStream but rather steves_house_of_discount_java.clearance_rack.DataOutputStream, then it may have a different interface.
In my experience Java usually does a pretty good job of choosing class names that don't conflict with other classes elsewhere in the ecosystem. I guess wordiness comes in handy sometimes.
I forget if Java imports common libraries without you having to ask. The file really might not have any import statements, and it simply knows to look in java.io for the DataOutputStream class.
 
4:34 PM
@Kevin that would be weird then. I only know of the hello world example that can get away without import afaik. Sometimes even just the import lib's name isn't enough and you have to specify the exact version too (which can have quite a lot of internal difference between each other)
 
The DOS is the java.io one
Well, I will investigate it more tomorrow.
 
FileInputStream.available doesn't return the size of the file, for one thing
 
user15071942
5:06 PM
Hi
 
user15071942
I'm trying to reduce my code by changing a flag.
 
user15071942
flag = 0
for n in range(0, lines, 2):
    for k in range(0, lines, 2):
        restrictions[n, k] = []
for n in range(lines):
    for k in range(1 - flag, lines, 2):
        if cells_values[n, k] != " ":
    if flag == 0:
        flag = 1
    else:
        flag = 0
 
The indentation is still b0rked, there's no indented block after if flag == 0:
 
user15071942
I think its okay now, sorry
 
Is the whole if flag == 0: thing supposed to be inside the if cells_values[n, k] != " ":?
 
user15071942
5:12 PM
Woh... no. There is come code for the if cells_values[n, k] != " ": but its big and I forgot to sinalize
 
Well, you can save 3 lines by replacing the if flag == 0: with flag = not flag. Other than that... I'm gonna need a while to figure out what this code is doing
I think you can replace 1 - flag with (n + 1) % 2, but I'm not sure if that's better
 
user15071942
I thought it, but the modulo always hits me
 
5:44 PM
@Roman The first nested loops change restrictions, but the second loop's only effect is to change a flag, right? It seems like there should be a closed form for that, depending on what restrictions was set to before this.
 
6:28 PM
howdy, folks! its been a while...
 
6:49 PM
been a while yeah
 
 
5 hours later…
wim
11:29 PM
Old chat room for advent-of-code has been defrosted here. Anyone can be RO (ask an existing RO). Please don't post spoilers for the most recent puzzles. Good luck!
 

« first day (4063 days earlier)      last day (868 days later) »